Closed Eseperio closed 3 years ago
Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:
Thanks!
This is an automated comment, triggered by adding the label status:need more info
.
I'll try to reproduce it.
So far I cannot reproduce it with simple example.
'modules' => [
'test1' => [
'class' => 'app\modules\test1\Module',
'modules' => [
'test2' => 'app\modules\test1\modules\test2\Module',
],
]
]
namespace app\modules\test1;
class Module extends \yii\base\Module {}
namespace app\modules\test1\modules\test2;
class Module extends \yii\base\Module {}
namespace app\modules\test1\controllers;
class TestController extends \yii\web\Controller
{
public function actionIndex()
{
return true;
}
}
namespace app\modules\test1\modules\test2\controllers;
class TestController extends \yii\web\Controller
{
public function actionIndex()
{
return true;
}
}
Debug panel works fine:
The problem might be with special config for yii2-usuario
. I'll try to check now again with this package exactly.
Still cannot reproduce.
'modules' => [
'test1' => [
'class' => 'app\modules\test1\Module',
'modules' => [
'test2' => 'app\modules\test1\modules\test2\Module',
'user' => 'Da\User\Module',
],
],
]
Ok, some information missing.
Settings controller has custom constructor with dependencies defined, which is why expects to be Da\User\Module
(see image below).
I think this is not a problem from yii2-usuario library or our project config because it only happens since Yii2-debug 2.1.14, previous versions worked fine (tested 2.1.0, 2.1.10,2.1.11,2.1.12,2.1.13,2.1.14).
Ok, this is why I asked how this is configured in the Slack thread. I'm asking again then.
Ok, i managed to reproduce the issue. I´ve created a sample project with all the conditions. Clone it and run composer install.
The issue happens if one controller in first level module is extending from a controller of another module which has custom constructor dependencies.
In the example we have example\emulated\frontend\controllers\OtherController
which extends from Da\User\Controller\SettingsController
, and that is what is causing the problem.
Thanks. I'm looking into it.
Indeed debug panel is showing that error but it happens on first/other
route. The controller handling it is:
namespace example\emulated\frontend\controllers;
use Da\User\Controller\SettingsController as BaseSettingsController;
class OtherController extends BaseSettingsController {}
and there is no surprise it throws the exception since there is different module calling it. At the same time route first/user/setting
(which is handled by the original controller Da\User\Controller\SettingsController
) works perfectly fine in the Debug panel.
Additionally when you visit /first/other
address in the browser the same exception is thrown.
So far two things are possible:
@Eseperio please take a look.
Direct access to the controller must throw an exception, because Module::createController
is always passing $id
and $module
to the constructor, and as you said, it is being called from another module.
The controller exists to be used with controllerMap
property, to override default one. But seems like Yii2-debug is creating an instance of this, and that is why it is getting the same exception.
So in controllerMap
you are passing the module there? Could you instruct here how do you configure it? I could not find anything in your app.
I´ve updated the project. Pull changes to see how settings controller is overrided.
I cannot see the rendered view for first/user/settings
but I can see it is run (so constructor is resolved) so indeed this is a bug in Debug panel. Although the fix might be tricky. We'll see.
Hmm, wait. Debug stops on first/settings
so this is the same situation as before and that configuration changes nothing.
The problem looks more like a case when the custom controller serving as a replacement for the original one is causing the Debug crash because it can be run directly but is misconfigured to do it properly.
The simplest solution for this is to keep this class out of the path that is configured as controllerNamespace
.
@Eseperio can you confirm this?
Moving outside controllerNamespace
stops the problem.
Ok, closing the issue then. Thanks for all the help.
Maybe Yii2 controller map guide needs an update indicating that overrided controllers should not be within controllerNamespace
.
I'm not sure, there might be a case where you want to run it directly.
What steps will reproduce the problem?
An application with a module which has yii2-usuario. AppModule->SubModule->Yii2-usuarioModule
What's expected?
See all available routes in routes panel
What do you get instead?
Argument 2 passed to Da\User\Controller\SettingsController::__construct() must be an instance of Da\User\Module, instance of namespace\of\submodule given
Additional info
Happens since 2.1.14