如何在 yii 框架中自动设置 url 友好
我刚刚学习了 yii 框架并阅读了本教程关于 yii 如何设置 url
I just learning yii framework and read this tutorial about yii how to setup url
但我不知道,假设我有 10 个控制器,我应该在配置文件中一个一个地定义控制器吗?有没有更好的方法来为所有控制器设置 url 友好,例如 www.yoursite.com/yourController/yourAction/yourID?
but I have no idea, suppose i have 10 controllers, should I define one by one controllers in the config file ? is there a better way to setup url friendly like www.yoursite.com/yourController/yourAction/yourID for all controller ?
我认为 codeigniter 是自动完成的...... yii 怎么样?
I think codeigniter did that automatically ... how about yii ?
推荐答案
在/protected/config/main.php 添加..
In /protected/config/main.php add..
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
),
),
在您的网络根目录中添加一个 .htaccess..
In your web root an .htaccess..
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# 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
相关文章