bede
(Bede214)
1
想請教下,如何解決這個問題。
設定如下
main.php
‘urlManager’=>array(
'urlFormat'=>'path'
'rules'=>array(
contactManagement/update/<id:\w+>/<groupId:\w+>'=>'<controller>/<action>'
.....
)
)
contactManagementController.php
public function actionUpdate($id, $groupId){
$this->loadModel($id);
}
Url在View file 用$this->createUrl(‘contactManagement/update’, array(‘id’=>1, ‘groupId’=>2)) 生成;
URL: ~yii/test/index.php/contactManagement/update?id=1&groupId=2
我已在UrlFormat設定其屬性為path.但所生成的URL並不是PATH Format。
執行$this->loadModel($id)會出錯誤:404
1。 如果我只傳一個變數id上來,是可以正常執行到。$this->loadModel($id);
2。另外我亦試過
public function actionUpdate($id, $groupId){
var_dump($id); //1
var_dump($groupId); //2
}
可以正常出到結果。
我是新手,試了很久也摸不著頭腦,請教各位大大。謝謝
yiqing95
(Yiqing 95)
2
contactManagement/update/<id:\w+>/<groupId:\w+>’=>’<controller>/<action>’
改成:
contactManagement/update/<id:\d+>/<groupId:\d+>'=>'contactManagement/update'
id应该是数字吧
还有你的配置:
'urlFormat' => 'path',
//'caseSensitive'=>false,
'showScriptName' => false, //隐藏index.php 要配合服务器重写(.htaccess in apache) 将所有请求导航到 index.php上
看yii的guide http://www.yiiframework.com/doc/guide/1.1/en/quickstart.apache-nginx-config
bede
(Bede214)
3
謝謝你的回覆。
在urlFormat加上了’showScriptName’ => false,
同時將w+ 改成 d+,還是出404錯誤。
我已有設定.htaccess file.
Options +FollowSymLinks
IndexIgnore /
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~yii/index.php
yiqing95
(Yiqing 95)
4
404 错误可能来自loadModel 方法
你先不要调用这个方法 先保证$id, $groupId 被正确赋值
用print echo 或者die 打印下这两个参数