-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web-controllers of modules are falsely auto-detected by the help command on the console #2821
Comments
Yeah seen this before, you need to separate console and web controllers. A convention could be to ha ve commands dir like in basic app. Will work on this. |
A simple fix for this would be to change Module::init() to the following: public function init()
{
if ($this->controllerNamespace === null) {
$class = get_class($this);
if (($pos = strrpos($class, '\\')) !== false) {
$this->controllerNamespace = substr($class, 0, $pos) . '\\'
. (Yii::$app instanceof \yii\console\Application ? 'commands' : 'controllers');
}
}
} But then it would not be possible to configure different namespaces for different environments anymore. When using console and web controllers in a module one is bound to the default values. |
I think the |
then there has to be a check in Module::createControllerByID() to not allow loading console controllers in web app and web controllers in console. |
Yes, I think so, but this probably should be done in Application. It's not a very trivial change though. |
Still the best way of separation would be to have different directories so it is clear from the location where the controller belongs to. The same issue is also with modules that can be used in different applications for example backend and frontend. |
Agree. It doesn't make sense to mix two types of controllers in the same directory. |
I'd also like to see two different directories, looks like to most intuitive solution to me. |
Fixed the Regarding whether So for the gii console support, we should introduce a |
…e controllers as available commands
If you register a module for the console (eg. gii) it's web-controllers are detected as console commands, somewhere around here: https://github.com/yiisoft/yii2/blob/master/framework/console/controllers/HelpController.php#L159
I wasn't sure if Reflection would be better and check instanceof console\Controller.
The text was updated successfully, but these errors were encountered: