eli*_*lon -1 php rest routing symfony1 http-method
我在Symfony应用程序中配置了以下路由:
label:
url: /label
param: { module: label, action: configure }
requirements: { sf_method: get }
label_create:
url: /label
param: { module: label, action: create }
requirements: { sf_method: post }
Run Code Online (Sandbox Code Playgroud)
链接executeConfigure和executeCreate行动.然后我有一个这样配置的表单:
<form action="<?php echo url_for('@label_create') ?>" method="POST">
<?php echo $form->renderHiddenFields() ?>
<input type="hidden" name="sf_method" value="post" />
<!-- more stuff here -->
</form>
Run Code Online (Sandbox Code Playgroud)
每当提交表单时executeConfigure,虽然据我所知,使用POST方法配置的路由应该避免并执行executeCreate.
如何区分这两个保持相同URL的操作?
谢谢!
我也有这个问题,并在一个旧的论坛消息中找到答案(http://oldforum.symfony-project.org/index.php/t/25750/).
如果它完全忽略了请求方法,则很可能使用常规sfRoute.您需要使用sfRequestRoute来使路由"方法感知".所以,在你的例子中你会做:
label:
url: /label
class: sfRequestRoute
param: { module: label, action: configure }
requirements: { sf_method: get }
label_create:
url: /label
class: sfRequestRoute
param: { module: label, action: create }
requirements: { sf_method: post }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1936 次 |
| 最近记录: |