I created a custom module with console command yii gii/module
I get a double entry with console command yii help
screenshot with double entry for module
this is the directory tree
- app/modules/vdreports/Module.php
- app/modules/vdreports/controllers/DefaultController.php
- app/modules/vdreports/views/default/index.php
Module.php
<?php
namespace appmodulesvdreports;
use Yii;
use yiibaseBootstrapInterface;
class Module extends yiibaseModule implements BootstrapInterface
{
public function bootstrap($app){
// print_r('ik ben in bootstrap'.PHP_EOL);
// var_dump($app->controllerMap);
foreach ($this->coreCommands() as $id => $command) {
if (!isset(Yii::$app->controllerMap[$id])) {
Yii::$app->controllerMap[$id] = $command;
}
}
}
public function init()
{
parent::init();
// custom initialization code goes here
}
public function coreCommands() {
return [
'vdreports' => 'appmodulesvdreportscontrollersDefaultController',
];
}
}
I patched it like this
app/vendor/yiisoft/yii2/console/controllers/HelpController.php
protected function validateControllerClass($controllerClass)
{
if (class_exists($controllerClass)) {
$class = new ReflectionClass($controllerClass);
// var_dump($class->isAbstract());
// var_dump($class->isSubclassOf('yiiconsoleController'));
// return !$class->isAbstract() && $class->isSubclassOf('yiiconsoleController');
return !$class->isAbstract() && $class->isSubclassOf('yiiconsoleController')
&& !strstr($controllerClass,'vdreports'); // 04/08/2024 Marnik : workaround to fix 'yii help'
}
return false;
}
Now I get a single entry for my module with console command yii help
as desired.
This is definitely not the right way. I don’t want to mess up a source file of the yii installation.
Can anybody help?
thanks
Marnik
Marnik Vanden Daele is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.