Have same route respond differently based on HTTP verb

时间:2018-07-25 04:23:06

标签: yii2 routes yii2-advanced-app

The following is a small snippet of my routes in _urlManager.php

["pattern" => 'POST /create_chain', 'route' => 'site/add-chain'],
["pattern" => '/create_chain', 'route' => 'site/create-chain']

As you can see for POST I want a different action to be called. But this does not work.

For now I've used the following solution on temporary basis:

"POST /create_chain" => "site/add-chain",
["pattern" => '/create_chain', 'route' => 'site/create-chain']

But I'm not OK with this solution. If anyone knows how I can integrate HTTP VERB in pattern, please comment or answer.

1 个答案:

答案 0 :(得分:0)

如果要使用数组语法配置动词,则应使用verb键:

["pattern" => '/create_chain', 'verb' => 'POST', 'route' => 'site/add-chain'],