Redirecting to login page instead of index page in Yii

When I go to my application, the page is redirected to the index page in Yii.

As required, I want to redirect to the user module login page the same way as /user/login .

Therefore, for this, I changed the sitecontroller code sitecontroller to user/login , but it showed an error.

Can someone tell me how to redirect the default user/login page instead of the index page? Any help and suggestions would be very noticeable.

+6
source share
3 answers

Check out this thread on the Yii Infrastructure Forum .

Copy / paste the answer (jodev):

No need to renew anything. All you have to do is open protected/config/main.php and add the following to the configuration array:

 return array( 'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..', 'name' => 'My application', 'defaultController' => 'myController/myAction', // <--- add this line and replace with correct controller/action 
+15
source

To redirect to a specific controller / action

 $this->redirect(array('controller/action')); 

Before moving on to the view and its form, let's clarify how View refers to a specific model. The controller may have this code:

 public function actionCreate() { $model=new Employee; /* Code for validation and redirect upon save. */ // If not saved, render the create View: $this->render('create',array( 'model'=>$model, // Model is passed to create.php View! )); } 
0
source

To redirect to the login page $ This-> redirect (array ('/ site / login'));

0
source

Source: https://habr.com/ru/post/909543/


All Articles