通过 sfGuard 传递删除方法
我在 Symfony 中有一个包含人员和组的应用程序,其中一个人可能拥有多个组的成员资格。为了从组中删除一个人,我目前在“groupMembers”模块中有一个操作,该操作采用“删除”方法并从多对多实体“group_membership”中删除该对。该路线目前看起来像这样:
remove_membership:
url: /group-membership/:group_id/:person_id
class: sfPropelRoute
options: { model: GroupMembership, type: object }
param: { module: groupMembers, action: remove }
requirements:
sf_method: [delete]
要执行此操作,用户需要登录,因此我在模块的 security.yml 中使用 sfGuard 对其进行限制:
remove:
is_secure: true
因此,在单击“删除”链接后,未登录的用户in 被带到登录屏幕,但单击“提交”后,请求不再是“删除”而是“获取”,这意味着将调用类似的 add_to_group 路由!
add_to_group:
url: /group-membership/:group_id/:person_id
param: { module: groupMembers, action: create }
...
有没有办法让 sfGuard 模拟删除操作并正确传递参数,或者我必须使用不同的路线?
I have an application with people and groups in Symfony, where a person may have a membership with multiple groups. To remove a person from a group, I currently have an action in a 'groupMembers' module that takes a 'delete' method and removes the pair from a many-to-many entity 'group_membership'. The route currently looks something like this:
remove_membership:
url: /group-membership/:group_id/:person_id
class: sfPropelRoute
options: { model: GroupMembership, type: object }
param: { module: groupMembers, action: remove }
requirements:
sf_method: [delete]
To perform this action, the user needs to be logged in, so I restricted it using sfGuard in the module's security.yml:
remove:
is_secure: true
So after clicking a 'remove' link, a user who isn't logged in is taken to the log in screen, but after clicking 'submit' the request is no longer a 'delete' but a 'get', meaning the similar add_to_group route is called instead!
add_to_group:
url: /group-membership/:group_id/:person_id
param: { module: groupMembers, action: create }
...
Is there any way to make sfGuard emulate a delete action and pass the parameters properly, or will I have to use a different route?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不编写自定义代码或编辑 sfGuard 插件的代码,似乎无法实现此目的。
请参阅
plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php
(其executeSignin
方法了解详细信息)如何处理登录。sfGuard
获取用户推荐人并使用 sfAction 的适当方法执行重定向。此重定向是通过使用 http 标头Location
执行的。所以浏览器会使用GET方法来接收url内容。您可以覆盖默认的
signin
操作,并执行从remove_membership
路由到将使用sfBrowser
组件模拟 POST 请求的操作的重定向,但我强烈建议您更改路由方案。It seems that there is no way to achieve this without writing custom code or editing code of sfGuard plugin.
See
plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php
(itsexecuteSignin
method for details) how sign in is handled.sfGuard
gets user referrer and performs redirect with appropriate method of sfAction. This redirect is performed by using http headerLocation
. So browser will use GET method to receive url content.You can override default
signin
action and perform redirects fromremove_membership
route to an action which will usesfBrowser
component to emulate POST request, but I highly recommend you to change routing scheme.