通过 sfGuard 传递删除方法

发布于 2024-11-26 22:05:18 字数 816 浏览 3 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-12-03 22:05:18

如果不编写自定义代码或编辑 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 (its executeSignin 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 header Location. So browser will use GET method to receive url content.

You can override default signin action and perform redirects from remove_membership route to an action which will use sfBrowser component to emulate POST request, but I highly recommend you to change routing scheme.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文