E
E
EvgMul2018-12-10 12:43:34
Yii
EvgMul, 2018-12-10 12:43:34

How to use module view in yii2?

Hello. Faced such a problem.
The authorization functionality has been moved to a separate module, which is called from the controller as follows:
frontend/controllers/SiteController.php

public function actions()
    {
        return [
            'login' => 'common\modules\user\controllers\actions\LoginAction',
            'logout' => 'common\modules\user\controllers\actions\LogoutAction',
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

Now I'm interested in LoginAction:
Run() method in common/modules/user/controllers/actions/LoginAction.php file
public function run()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->controller->goHome();
        }

        $model = new LoginForm();
        $request = \Yii::$app->request;

        if ($model->load($request->post()) && $model->validate()) {
            $user = $model->getUser();
            if (!$model->rememberMe) {
                $this->expire = $this->expireNotRemember;
            }
            if ($this->service->login($user, $this->expire, $request)) {
                if (\Yii::$app->user->login($user, $this->expire)) {
                    return $this->controller->goHome();
                }
            }
        }

        $model->password = '';
        return $this->controller->render('login', [
            'model' => $model,
        ]);
    }

The method is called, but it tries to display the view from the frontend\views\site\login.php directory.
Accordingly, I get an error:
The view file does not exist: ***\frontend\views\site\login.php

Tell me, please, what and where I did not register in the configs so that the view is loaded from the module?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-12-10
@webinar

Here is an example, just with the view setting for Standalone Actions:
https://www.yiiframework.com/doc/guide/2.0/en/stru...
https://www.yiiframework.com/doc/api/2.0/ yii-web-v...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question