2012-07-17 33 views
0

「索引」我如何從http://localhost/dashboard/index/create的Yii - 取下URL

刪除index我有我的urlManager的設置是這樣的:

'urlManager' => array(
    'urlFormat' => 'path', 
    'showScriptName' => false, 
    'rules' => array(
     '<controller:\w+>/<id:\d+>' => '<controller>/view', 
     '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', 
     '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 
    ), 
), 

而這給了我乾淨的網址,這樣http://localhost/dashboard其中dashboard是模塊的默認控制器名爲indexController。現在

,我遇到的問題是,我如果不首先把index e.g訪問模塊控制器的其它動作。如果我想打電話給actionCreateindexController,我總是不得不說http://localhost/dashboard/index/create

有什麼辦法可以擺脫index,只是這樣調用它:http://localhost/dashboard/create

這是我的模塊是如何在main.php配置:

'modules' => array(
    ... 
    'dashboard' => array(
     'defaultController' => 'index' 
    ), 
    ... 
), 

預先感謝您:-)

回答

3

儘量安排你的數組像這樣(把與儀表盤開頭的行你urlManager組件下) :

array(
    ... 
    'components' => array(
    ... 
    'urlManager' => array(
     ... 
     'rules' => array(
      'dashboard/<action:\w+>' => 'dashboard/index/<action>' 
    ), 
    ), 
), 
); 
+0

這解決了我的問題,但現在我一直遇到如下錯誤:'錯誤404:找不到操作'儀表板/儀表板/創建'。這是副作用嗎?我稱之爲「http:// localhost/dashboard/create」這樣的動作,但我不知道如何在URL上使用2個「dashboard」。任何想法之前,我關閉此線程? – Sthe 2012-07-18 06:49:36

+0

嗯,我不明白爲什麼會添加一個額外的儀表板。 .htaccess能做什麼嗎? – Ansari 2012-07-18 06:52:55

+0

這是我在我的.htaccess:! 'RewriteEngine敘述上 的RewriteCond%{} REQUEST_FILENAME -f 的RewriteCond%{} REQUEST_FILENAME -d 重寫規則。 index.php' – Sthe 2012-07-18 07:19:33

0

您可以創建.htaccess file爲:

RewriteEngine on 
RewriteBase /project_folder_NAME 
# if a directory or a file exists, use it directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

# otherwise forward it to index.php 
RewriteRule . index.php