简体   繁体   English

在Yii中重定向到登录页面而不是索引页面

[英]Redirect to login page instead of index page in Yii

When I am going to my application, the page is redirect to the index page in Yii. 当我转到我的应用程序时,页面将重定向到Yii中的索引页面。

As per requirement, I want to redirect to the login page of the user module just like /user/login . 根据要求,我想重定向到用户模块的登录页面,就像/user/login

So for doing that I have changed the sitecontroller code index to user/login , but it showed an error. 因此,为此,我已将sitecontroller代码索引更改为user/login ,但它显示错误。

Can some one tell me how to redirect the user/login page by default instead of index page? 有人可以告诉我如何默认重定向user/login页面而不是索引页面? Any help and suggestions will be highly appreciable. 任何帮助和建议都将非常值得一提。

Check this thread on Yii framework forum . 在Yii框架论坛上查看此主题

Copy/paste of the answer (by jodev ): 复制/粘贴答案(通过jodev ):

No need to extend anything. 无需任何扩展。 All you have to do is open up protected/config/main.php and add the following to the config array: 您所要做的就是打开protected/config/main.php并将以下内容添加到配置数组中:

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

To redirect to a particular controller/action 重定向到特定的控制器/操作

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

Before getting to the View and its form, let's be clear as to how the View accesses the specific Model. 在进入View及其表单之前,让我们清楚View如何访问特定的Model。 A 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!
    ));
}

要重定向到登录页面$ this-> redirect(array('/ site / login'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM