2012-02-28 83 views
6

當我要去我的應用程序時,頁面會重定向到Yii的索引頁面。重定向到登錄頁面而不是Yii的索引頁面

按照要求,我想重定向到用戶模塊的登錄頁面,就像/user/login一樣。

因此,爲此我已將sitecontroller代碼索引更改爲user/login,但顯示錯誤。

有人可以告訴我如何重定向user/login默認頁而不是索引頁?任何幫助和建議都將非常可觀。

回答

15

檢查this thread on Yii framework forum

複製/答案的糊料(jodev):

無需擴展任何內容。所有你需要做的就是打開 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 
+3

的代碼將是這樣'返回陣列( '基本路徑'=>目錄名(__ FILE __)。DIRECTORY_SEPARATOR。 '..', '名稱'=> '我的應用', 'defaultController'=>「用戶/ Login',' – NewUser 2012-03-21 07:55:07

0

重定向到一個特定的控制器/動作

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

得到的觀及其之前形式,讓我們清楚視圖如何訪問特定的模型。控制器可以有這樣的代碼:

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

重定向登錄頁面 $這 - >重定向(陣列( '/站點/登錄'));

+1

yes這會重定向到登錄頁面,但是如果您使用用戶模塊並且希望o重定向到用戶登錄頁面,它將不起作用。 – NewUser 2012-02-29 11:00:21