yii2-gii icon indicating copy to clipboard operation
yii2-gii copied to clipboard

Crud autocomplete

Open pana1990 opened this issue 9 years ago • 9 comments

migrate from https://github.com/yiisoft/yii2/issues/8710

@samdark i think we could include $modelsPath to look for ActiveRecord's models.

what do you think about it?

pana1990 avatar Oct 21 '15 15:10 pana1990

I don't think it's a good idea to require specifying any config options for it. Gii is usually used at the very start of the project so it would be a big hassle to specify config options from the very start. It could possibly scan the whole project but it would require re-scanning it constantly which could create significant delays in operation.

samdark avatar Oct 21 '15 15:10 samdark

it should be specifying in config file (basic and advanced templates) by default, what's the problem?

pana1990 avatar Oct 21 '15 17:10 pana1990

The problem is that noone's forcing you to store models under models directly. You could use sub-directories or even other directories.

samdark avatar Oct 21 '15 18:10 samdark

if you want store models under another folder you may add path in $modelsPath, for example :

if (YII_ENV_DEV) {    
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',      
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],  
        'generators' => [ //here
            'crud' => [ // generator name
                'class' => 'yii\gii\generators\crud\Generator', 
                'modelsPath ' => [
                   '@app/models/',  // by default in basic template, it looking for subdirectories too
                   '@modules/user/models/', // custom
                   ... // another paths
                 ]        
            ]
        ],
    ];
}

pana1990 avatar Oct 22 '15 01:10 pana1990

How to deal with the fact that in basic and advanced models are stored at completely different locations?

samdark avatar Oct 22 '15 07:10 samdark

My idea is configuring in basic and advanced models's path by default, in advanced could be this:

// in /environments/dev/frontend/config/main-local.php path
if (YII_ENV_DEV) {    
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',      
        'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],  
        'generators' => [ //here
            'crud' => [ // generator name
                'class' => 'yii\gii\generators\crud\Generator', 
                'modelsPath ' => [
                   '@frontend/models/',  
                   '@backend/models/',
                   '@common/models/',
                 ]        
            ]
        ],
    ];
}

pana1990 avatar Oct 22 '15 07:10 pana1990

Hmm... instead of autocompleting by model name we can autocomplete namespaces i.e. we know root dir for namespace and deeper levels and class name could be obtainer by reading that dir. That way no config would be required.

samdark avatar Oct 22 '15 08:10 samdark

it sounds good for me.

how do you do it? including autoCompleteAjax method or similar?

pana1990 avatar Oct 23 '15 10:10 pana1990

Yes.

samdark avatar Oct 23 '15 13:10 samdark