1

Всем привет! Использую модуль Yii2-user. Нужно было сделать так, чтобы при входе неавторизованного пользователя не было никакого меню, а только форма ввода логина и пароля. Для этого сделал следующие вещи. Создал модуль users.

namespace app\modules\users;

class Module extends \dektrium\user\Module
{
    public $controllerMap = [
        'admin'    => 'dektrium\user\controllers\AdminController',
        'registration' => 'dektrium\user\controllers\RegistrationController',
        'security'     => 'app\modules\users\controllers\SecurityController',// Переопределенный контроллер
        'recovery'     => 'dektrium\user\controllers\RecoveryController',
        'settings'     => 'dektrium\user\controllers\SettingsController',
        'profile'      => 'dektrium\user\controllers\ProfileController',
    ];
}

В котором переопределил контроллер SecurityController на свой

namespace app\modules\users\controllers;

use dektrium\user\controllers\SecurityController as BaseSecurityController;

class SecurityController extends BaseSecurityController
{
    public function actionLogin()
    {
        $this->layout = 'main-login';
        return parent::actionLogin();
    }
}

В своем модуле переопределил основную вьюху, всю выводить не буду, только покажу проблемный участок.

<div class="row">
            <div class="col-xs-12">
                <?= Html::a(
                    Yii::t('user', 'Forgot password?'),
                    ['/user/recovery/request']
                ) ?>
            </div>
        </div>

Как видно, ссылка ведет на '/user/recovery/request', но при нажатии на ссылку попадаю на '/user/forgot', что приводит к 404 ошибке. Как я понял это происходит по той причине, что у самого модуля dektrium/yii2-user прописано

public $urlRules = [
        '<id:\d+>'                               => 'profile/show',
        '<action:(login|logout|auth)>'           => 'security/<action>',
        '<action:(register|resend)>'             => 'registration/<action>',
        'confirm/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'registration/confirm',
        'forgot'                                 => 'recovery/request',// Тут правило которое меняет маршрут
        'recover/<id:\d+>/<code:[A-Za-z0-9_-]+>' => 'recovery/reset',
        'settings/<action:\w+>'                  => 'settings/<action>'
    ];

Теперь вопрос: как правильно исправить эту ситуацию, чтобы не возникала ошибка 404?

1 ответ 1

1

В конфиге переопределите пути для вашего контроллера и views.

'components' => [
...
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@dektrium/user/views' => '@app/modules/users/views',
                ],
            ],
        ],
...
]

'modules' => [
...
        'user' => [
            'controllerMap' => [
                'security' => 'app\modules\users\controllers\SecurityController',
            ],
        ],
...
]

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.