yii2-gii
yii2-gii copied to clipboard
Crud autocomplete
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?
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.
it should be specifying in config file (basic and advanced templates) by default, what's the problem?
The problem is that noone's forcing you to store models under models
directly. You could use sub-directories or even other directories.
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
]
]
],
];
}
How to deal with the fact that in basic and advanced models are stored at completely different locations?
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/',
]
]
],
];
}
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.
it sounds good for me.
how do you do it? including autoCompleteAjax method or similar?
Yes.