yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
203 stars 192 forks source link

Crud autocomplete #93

Open pana1990 opened 9 years ago

pana1990 commented 9 years ago

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?

samdark commented 9 years ago

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.

pana1990 commented 9 years ago

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

samdark commented 9 years ago

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

pana1990 commented 9 years ago

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
                 ]        
            ]
        ],
    ];
}
samdark commented 9 years ago

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

pana1990 commented 9 years ago

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/',
                 ]        
            ]
        ],
    ];
}
samdark commented 9 years ago

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.

pana1990 commented 9 years ago

it sounds good for me.

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

samdark commented 9 years ago

Yes.