How to set home page in Yii2

773 views Asked by At
public function actionIndex() {
    $this->layout = 'landing';
    $loginForm = new LoginForm();
    if (\Yii::$app->request->getIsPost()) {
        $loginForm->load(\Yii::$app->request->post());
        if ($loginForm->validate()) {
            $user = $loginForm->getUser();
            \Yii::$app->user->login($user);
            return $this->goHome();
        }
    }
}

method goHome() sends to the home page. I have added '' => 'site/index' to the URL Manager earlier to send people to the SiteController and Index action, but Yii2 does not do anything. How to set up a correct home page rule?

1

There are 1 answers

0
rakhmatov On

You should write homeUrl parameter on config/main.php. For example:

return [
        'id' => 'app-frontend',
        'basePath' => dirname(__DIR__),
        'bootstrap' => ['log'],
        'homeUrl' => ['some/home-url-example'],
        'modules' => [
          ...
        ],
       ...
    ]