好时光。有关于为urlManager设置规则的问题。需要做的是能够传递id defaultController控制器。例如,我的defaultController =“default”,我需要传递参数,即无论你输入http://site.ru/abc什么来导致控制器默认,action = index并且传递id参数的值为abc。
答案 0 :(得分:0)
你可以试试这个:
我想你使用Apache:转到httpd.conf然后将Document Root更改为你的Yii项目:
Document Root ".../www/your_yii_project"
通过编辑config文件夹中的main.php配置路由:当你传递id的值时,将调用SiteController中的actionIndex()。
.......
'urlManager' => array(
'showScriptName' => false,
'urlFormat' => 'path',
'caseSensitive' => false,
'rules' => array(
........
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<id:\w+>' => 'site/index'
.....
)
),
.....
我的SiteController如:
class SiteController extends CController
{
public function actionIndex()
{
var_dump($_GET);
}
}
最后您应该看到此链接http://www.yiiframework.com/wiki/214/url-hide-index-php/隐藏您网址中的index.php。而已。这是我的结果:
http://localhost:81/abc
它返回: 数组(大小= 1) 'id'=&gt;字符串'abc'(长度= 3)