相同模式不同的路线

时间:2017-04-04 04:29:06

标签: php url yii2 uri httpverbs

如何定义两个具有两个差异方法的相同URI? 例如:

 'owners/<user_id:\d+>/pets' => 'pets/index', //using GET
 'owners/<user_id:\d+>/pets' => 'pets/create',//using POST

我在下面尝试以下代码:

 'GET owners/<user_id:\d+>/pets' => 'pets/index',
 'POST owners/<user_id:\d+>/pets' => 'pets/create',

但我的问题是如果我有这个代码它总是显示404找不到而不是405?

请注意,我已在行为中添加了此内容:

'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'index'  => ['get'],
                    'create'  => ['post'],
                ],
            ],

1 个答案:

答案 0 :(得分:0)

我会尝试这个(按此顺序):

getNumber(1)