Yii2 login URL with a twist

I have a similar problem with the default user/login route however things are a little complicated by my use of a plugin user management module ( yii2-user )

My config file configures the module and it works well but trying to overide user/login in the components section

        'user' => [

           'loginUrl' => ['/user/security/login'],

           'allowAutoLogin' => false


fails miserably with Yii steadfastly returning user/login.

earlier in the config the dektrium user module is defined.

     'user' => [

        'class' => 'dektrium\user\Module',

        'confirmWithin' => 21600,

        'cost' => 12,

        'admins' => ['admin']


I have tried to override it in a beforeAction in the SiteController but looking at the log files this file is only executed well after the initial call to user/login as you can see here ( lines 6 and 13 ) …

1	10:42:14.305	trace	yii\base\Application::bootstrap	Bootstrap with dektrium\user\Bootstrap::bootstrap()

2	10:42:14.305	trace	yii\base\Module::getModule	Loading module: user

3	10:42:14.306	trace	yii\base\Module::getModule	Loading module: debug

4	10:42:14.306	trace	yii\base\Application::bootstrap	Bootstrap with yii\debug\Module::bootstrap()

5	10:42:14.307	trace	yii\web\UrlRule::parseRequest	Request parsed with URL rule: <controller:\w+>/<action:\w+>

6	10:42:14.307	trace	yii\web\Application::handleRequest	Route requested: 'user/login'

7	10:42:14.308	error	yii\web\HttpException:404	exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "user/login".' in /var/www/vhosts/ioiotrap/vendor/yiisoft/yii2/base/Module.php:461

Stack trace:

#0 /var/www/vhosts/ioiotrap/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('user/login', Array)

#1 /var/www/vhosts/ioiotrap/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

#2 /var/www/vhosts/ioiotrap/backend/web/index.php(18): yii\base\Application->run()

#3 {main}

Next exception 'yii\web\NotFoundHttpException' with message 'Unable to resolve the request "user/login".' in /var/www/vhosts/ioiotrap/vendor/yiisoft/yii2/web/Application.php:95

Stack trace:

#0 /var/www/vhosts/ioiotrap/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))

#1 /var/www/vhosts/ioiotrap/backend/web/index.php(18): yii\base\Application->run()

#2 {main}

8	10:42:14.308	trace	yii\base\Controller::runAction	Route to run: site/error

9	10:42:14.310	info	yii\web\Session::open	Session started

/var/www/vhosts/ioiotrap/backend/controllers/SiteController.php (21)

10	10:42:14.311	info	yii\db\Connection::open	Opening DB connection: mysql:host=localhost;dbname=ioiotrapsite

/var/www/vhosts/ioiotrap/backend/controllers/SiteController.php (21)

11	10:42:14.312	info	yii\db\Command::query	SELECT * FROM `auth_item` WHERE `name`='admin'

/var/www/vhosts/ioiotrap/backend/controllers/SiteController.php (21)

12	10:42:14.313	trace	yii\rbac\DbManager::checkAccessRecursive	Checking role: admin

/var/www/vhosts/ioiotrap/backend/controllers/SiteController.php (21)

13	10:42:14.313	info	application	iHm  logmessage at beforeAction

/var/www/vhosts/ioiotrap/backend/controllers/SiteController.php (29)

A manual call to route /user/security/login works fine and using this in the site menu bar the route is not overridden but references to that route in the vendor source code are overridden by the time they reach the browser to user/login.

So, with both a module and a component section in the config file is the component section being ignored and if not how can I get the framework to accept the modules user/security/login and stop replacing it?

I just discover you have to change views/layouts/main.php:


['label' => 'Login', 'url' => ['/site/login']] :




['label' => 'Login', 'url' => ['/user/login']] :


This work for me.

I’ve the same issue, is anyone have a solution for this?

Have you try this on your components section:

'user' => [

    'identityClass' => 'dektrium\user\models\User',