Open rackycz opened 2 years ago
@yiisoft/reviewers need your opinion.
Was one reason for me to create giiant, back then :) https://github.com/schmunk42/yii2-giiant
Yii 2 is quite oldschool regarding the inheritance vs composition debate so adding additional layer of inheritance would not be a terrible thing but we all know that it's not a good thing, right? ;)
Another option would be to move the generated code into Traits
and just have a more or less empty class using them.
I remember @cebe talking about a new version that would patch the file while keeping your changes, right Carsten?
Thanks @schmunk42 for the base model idea in giiant. Base model regeneration after modifying a database tables is something I do daily. In addition saving gii form data for reuse would be fantastic. In Giiant it is realized and useful.
I remember @cebe talking about a new version that would patch the file while keeping your changes, right Carsten?
yeah, that's an idea which would be really cool to implement, but I had no time to play with that.
Hi. Sometimes it might be handy to split model into 2 classes: 1) class UserBase extends \yii\db\ActiveRecord - contains all code generated by Gii (placed in folder "models/base") 2) class User extends UserBase (placed in standard folder "models" and is empty at the beginning)
UserBase contains generated code while User contains code that was produced by the programmer. The programmer can also decide to use pure PHP in model User while in UserBase can be Yii-dependent code. But it is not a rule. Code then can be more readable as classes are shorter etc.
Programmer still uses the class User as usually. No changes here.
So I am suggesting this as a new option (checkbox) in Gii.
My solution:
I extended yii\gii\generators\model\Generator and following is the result. Only method generate() was changed a little. See $this->splitModelIntoBaseClass below. (In comments are also mentioned all JS and form changes)
If you think this might be usefull for others, you can check/use my code below. But it is nothing special. Just an idea.
Good luck to yo,u Yii.
PS: Gii is amazing. When I compare it to other frameworks, you are ahead by miles as Gii is delivered directly by Yii and one has all functionalities in one bundle.