一、Url重新規(guī)則
1、將項目的地址修改成靜態(tài)模式(偽靜態(tài)===Url路由管理): a)Index.html === index.php?r=index/index b)Cate-1.html === index.php?r=article/list&cid=1 c)Art-1.html === index.php?r=article/index&aid=1 d)想完成上述功能: i.需要有apache功能模塊的支持 url重寫模塊 ii.修改apache配置文件,apache安裝目錄/Conf/httpd.conf 1.LoadModule rewrite_module modules/mod_rewrite.so 2.AllowOverride All iii.重啟apache,使其修改生效 e)使用yii框架的URL路由功能: i.隱藏入口文件 1.編輯.htaccess文件 a)RewriteEngine On b)RewriteCond %{REQUEST_FILENAME} !-f c)RewriteCond %{REQUEST_FILENAME} !-d d)RewriteRule . index.php 2.編輯項目配置文件 bbs/protected/config/main.php a)'urlManager'=>array( i.'urlFormat'=>'path',//開啟pathinfo格式 ii.'showScriptName'=>false,//index.php 隱藏入口文件 iii.‘urlSuffix’=>’.html’, iv.'rules'=>array( 1.‘index’=>’index/index’, 2.‘cate-<cid:d+>’=>’article/list’, 3.‘a(chǎn)rt-<aid:d+>’=>’article/index’, v.), b)),
二、Yii框架的$this->createUrl方法
Yii框架的$this->createUrl方法會自動根據(jù)url規(guī)則產(chǎn)生對應(yīng)的超鏈接,因此,在項目開發(fā)過程當(dāng)中,所有的超鏈接我們都需要使用createUrl幫助我們產(chǎn)生。
相關(guān)文章教程推薦:yii框架