Yii-删除';索引';来自URL


Yii - Remove 'index' from URL

如何从http://localhost/dashboard/index/create 中删除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>',
     ),
 ),

这给了我干净的URL,比如http://localhost/dashboard,其中dashboard是一个带有默认控制器indexController的模块。

现在,我遇到的问题是,如果不首先放入index,我就无法访问模块控制器的其他操作。例如,如果我想在indexController中调用actionCreate,我总是要说http://localhost/dashboard/index/create

有没有什么方法可以去掉index,然后这样称呼它:http://localhost/dashboard/create

这就是我的模块在main.php:中的配置方式

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

提前感谢:-)

试着这样排列您的数组(将以仪表板开头的行放在urlManager组件下):

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

您可以为此创建.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