我正在使用Yii,並且我有一個名爲User
的控制器以及一些CRUD操作的操作。我添加了一個新的動作如下:使用params返回404的控制器操作未找到
public function actionEmbedded($field, $action, $id){
/* code */
}
要訪問這個動作的URL應該是
/user/embedded/field/logins/action/view/id/5542ab0cb0db0ab000000001
但這返回404 Not found error
。
然而,當我改變參數之一$_id
而不是$id
...
public function actionEmbedded($field, $action, $_id){
/* code */
}
...它可以訪問就像預期
/user/embedded/field/logins/action/view/_id/5542ab0cb0db0ab000000001
任何行動想法爲什麼?我的任何參數名稱是否保留?我在其他操作中使用了$id
,如果這可能是導致此行爲的原因。
UPDATE: 下面是從我的config.php文件urlManager碼。
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=> false,
'rules'=>array(
// Handles differen API versions
'api/1.0/<action:\w+>/*' => 'api_1_0_/<action>',
array('api_1_1_/<action>', 'pattern'=>'api/1.1/<action:\w+>', 'verb' => 'GET'),
//array('api_1_1_/Post<action>', 'pattern'=>'api/1.1/<action:\w+>/*', 'verb' => 'POST'),
// User specific API calls (starts with users/me)
array('api_1_1_/prices', 'pattern'=>'api/1.1/prices/<market:\w+>/<biddingArea:\w+>/hour/<period:\w+>', 'verb' => 'GET'),
array('api_1_1_/view/model/users/id/me', 'pattern'=>'api/1.1/users/me', 'verb' => 'GET'),
array('api_1_1_/listEmbeddedArray/model/users/id/me/array/contracts', 'pattern'=>'api/1.1/users/me/meters', 'verb' => 'GET'),
array('api_1_1_/view/model/units/id/<id>', 'pattern'=>'api/1.1/users/me/meters/<id:\w+>', 'verb' => 'GET'),
//array('api_1_1_/viewEmbeddedArray/model/users/id/me/array/contracts/ean/<ean>', 'pattern'=>'api/1.1/users/me/meters/<source:\w+>/<ean:\w+>', 'verb' => 'GET'),
//array('api_1_1_/series', 'pattern'=>'api/1.1/users/me/meters/<source:\w+>/<ean:\w+>/series/<query:\w+>', 'verb' => 'GET'),
//array('api_1_1_/series/source/<source>/ean/<ean>/resolution/<resolution>/query<query>', 'pattern'=>'api/1.1/users/me/meters/<source:\w+>/<ean:\w+>/series/<resolution:\w+>/<query:\w+>', 'verb' => 'GET'),
//array('api_1_1_/view/model/unit/id/<id>', 'pattern'=>'api/1.1/users/me/meters/<id:\w+>', 'verb' => 'GET'),
array('api_1_1_/series/id/<id>', 'pattern'=>'api/1.1/users/me/series/<id:\w+>', 'verb' => 'GET'),
array('api_1_1_/list', 'pattern'=>'api/1.1/users/me/<model:\w+>', 'verb' => 'GET'),
array('api_1_1_/view', 'pattern'=>'api/1.1/users/me/<model:\w+>/<id:\w+>', 'verb' => 'GET'),
array('api_1_1_/delete', 'pattern'=>'api/1.1/users/me/<model:\w+>/<id:\w+>', 'verb' => 'DELETE'),
// General API calls
array('api_1_1_/download', 'pattern'=>'api/1.1/download/<model:\w+>', 'verb' => 'GET'),
array('api_1_1_/series', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/series', 'verb' => 'GET'),
array('api_1_1_/listEmbeddedArray', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/<array:\w+>', 'verb' => 'GET'),
array('api_1_1_/updateEmbeddedArray', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/<array:\w+>/<ean:\w+>', 'verb' => 'PUT'),
array('api_1_1_/deleteEmbeddedArray', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/<array:\w+>/<ean:\w+>', 'verb' => 'DELETE'),
array('api_1_1_/viewEmbeddedArray', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/<array:\w+>/<ean:\w+>', 'verb' => 'GET'),
array('api_1_1_/createEmbeddedArray', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>/<array:\w+>', 'verb' => 'POST'),
array('api_1_1_/list', 'pattern'=>'api/1.1/<model:\w+>', 'verb' => 'GET'),
array('api_1_1_/view', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>', 'verb' => 'GET'),
array('api_1_1_/update', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>', 'verb' => 'PUT'),
array('api_1_1_/delete', 'pattern'=>'api/1.1/<model:\w+>/<id:\w+>', 'verb' => 'DELETE'),
array('api_1_1_/create', 'pattern'=>'api/1.1/<model:\w+>', 'verb' => 'POST'),
),
),
您似乎在使用url管理器或其他東西,否則您的網址看起來像'/index.php?r = user/embedded&id = 5542ab0cb0db0ab000000001'。你如何使用該類型的網址訪問您的操作? – deacs
是的,我使用urlManager。我試圖關閉它,並使用'/index.php?r=user/ embedded&id = 525ec506df6232341c000033&field = logins&action = view',但是它引起了同樣的問題... – luttkens
你能否發佈urlmanager代碼? – deacs