Yii 1.1: abstractmodelgenerator

Custom model generator for gii that generates an abstract class and a concrete class of a specified model

Have you ever found yourself stuck when you put some custom code inside a model file generated and for some reason need to regenerate the same model using Gii? For these reason I created this gii's generator to apply the following design pattern.

Every time you generate a model two files will be created. One as a abstract class named as BaseUser.php and saved inside protected/models/base and another concrete class named User.php extending the BaseUser.php and saved inside protected/models. All rules generate by gii will be printed inside the abstract class. If you need to customize some aspect of the User you will need to modify the concrete class.

The generator provide an flexible way to enable/disable the generation of the concrete class. This way we avoid the problem of lose our custom code that usually would be overridden by a schema modification.

The paths described above can be modified during the generation process.


  • Yii 1.1.8 (I didn't test on earlier versions, but my guess is that should work)


  • Unzip the model.zip file and put the contents inside protected/gii/generators.
  • Customize your protected/config/main.php in order to activate a custom generator path for gii. This can be done with the following snippet:
'modules' => array(
    'gii' => array(
    'class' => 'system.gii.GiiModule',
    'password' => 'gii',
    'generatorPaths' => array(
        'ipFilters' => array('', '::1'),
  • Now you can access your gii module and generate all models.


Total 5 comments

#10683 report it
developerworks at 2012/11/15 12:04am
sorry updated and adding the original modelPath you can specified

sorry, just updated to yii 1.1.2 and no make better

#10682 report it
developerworks at 2012/11/15 12:01am
updated the extension to yii 1.1.12 and make better readable generated code
#4879 report it
ololo at 2011/08/24 05:37am
good practice, but ...

Have you try Giix? It can do the same thing, if there any advantages of your extension?

#4877 report it
William Lepinski at 2011/08/23 08:25pm
Thanks :)

I filled in an issue but I think that qiang.xue don't agree with us. Well, at least we have the extension to work for us.

#4876 report it
Pomstiborius at 2011/08/23 12:58pm
Great job

Great extension. It should be part of Yii core. Maybe in version 1.1.9... :)

Leave a comment

Please to leave your comment.

Create extension