Symfony:覆盖FOSUserBundle重置控制器 [英] Symfony: Override FOSUserBundle Resetting Controller
问题描述
我正在尝试覆盖FOSUserBundle的重置控制器".我自己的UserBundle覆盖了整个捆绑包,例如,模板,但这是我第一次尝试覆盖Controller,这似乎是我做错了什么.
I'm trying to override the Resetting Controller of the FOSUserBundle. My own UserBundle is overriding the whole bundle, and it's working fine for e.g. templates but it's the first time I try to override a Controller and it seems like I'm doing something wrong.
以这种方式尝试(由于控制器的其余部分仍然是默认选项,因此仅在第一行进行复制):
Trying it that way (only copying in the first line since the rest of the controller is still the default one):
namespace UserBundle\Controller\User;
use FOS\UserBundle\Controller\ResettingController as BaseController;
...
class ResettingController extends BaseController{
...
重置密码"按钮位于我的登录页面上.
The "Reset Password" button is located on my login page.
我要实现的是对 checkEmailAction 进行一些自定义.我想检查请求重设密码的人是否是锁定"用户,并且还要为每个请求发送正确的响应消息".控制器的其余部分可以保持不变. 我添加了一些转储和一个死";进入代码以检查是否有任何输出,但没有输出.
What I'm trying to achieve is some customization for the checkEmailAction. I want to check whether the person who's requesting the password reset is a "locked" user or not, and also send a correct "Response Message" for each request. The rest of the Controller can stay the same. I added some dumps and a "die;" into the code to check if there's any output but there is none.
我最好从哪里开始寻找?根据文档 https://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html 我不应该超过已经做的事情.
Where do I best start looking? According to the documentation https://symfony.com/doc/current/bundles/FOSUserBundle/overriding_controllers.html I shouldn't have to be more than I'm already doing.
推荐答案
我的解决方案: 我的错误是在routing.yml文件中.我首先有:
My solution: my mistake was in the routing.yml file. I first had:
fos_user_resetting_reset: path: /resetting/request defaults: { _controller: UserBundle:Resetting:request }
但是我从来没有真正想要覆盖请求方法,而且名称Fos_user_resetteing_reset与 request 不匹配.
But I never actually wanted to override the request method and also the name Fos_user_resetteing_reset didn't match with request.
所以我的最终解决方案是:
So my final solution:
fos_user_resetting_send_email:
path: /resetting/send-email
defaults: { _controller: UserBundle:User\Resetting:sendEmail }
fos_user_resetting_check_email:
path: /resetting/check-email
defaults: { _controller: UserBundle:User\Resetting:checkEmail }
这样,我只覆盖了这两种方法,其余的重置"控制器仍然使用默认方法. :)
this way I'm only overriding these two methods and the rest of the Resetting controller still picks up on the default one. :)
这篇关于Symfony:覆盖FOSUserBundle重置控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!