Yii 2.0: yii2-gouble-model-gii

Generates two ActiveRecord class for a database table. An empty one you can extend and and a base one.


This generator generates two ActiveRecord class for the specified database table. An empty one you can extend and a Base one which is the same as the original model generatior.


The preferred way to install this extension is through composer.

Either run

$ php composer.phar require "claudejanz/yii2-mygii": "dev-master"

or add

"claudejanz/yii2-mygii": "dev-master"

to the require section of your composer.json file.


//if your gii modules configuration looks like below:
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yii\gii\Module';
//remove this two lines
//Add this into common/config/main-local.php
    'bootstrap' => 'gii',
    'modules' => [
        'gii' => [
            'class' => 'yii\gii\Module',
            'generators' => [
                'doubleModel' => [
                    'class' => 'claudejanz\mygii\generators\model\Generator',

Total 6 comments

#19054 report it
klod at 2015/03/04 05:21am

For database changes support.

The base one will be regenerated each time I make db changes. The other one takes my code.

#19053 report it
robsch at 2015/03/04 02:57am
Why should I want this extension?

What is the advantage to have two model classes?

#17892 report it
klod at 2014/08/07 05:13am
Thanks Maris

Modification done. Thanks

#17891 report it
Maris at 2014/08/07 03:46am
relations broken

Again wrong.


<?php foreach ($relations as $name => $relation): ?>
use <?= $generator->ns ?>\<?= $relation[1] . ";\n" ?>
<?php endforeach; ?>

Instead of

<?php foreach ($relations as $name => $relation): ?>
use <?= $generator->ns.'\\'.$name . ";\n" ?>
<?php endforeach; ?>

For has many relation your code will generate app\models\Users instead of app\models\User

#17890 report it
klod at 2014/08/06 08:16pm
Thanks Maris

I have added related models to use list. Should work now. Thanks

#17885 report it
Maris at 2014/08/06 05:05am
relations broken

In your generator relations are broken, because related models is in different namespace.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet