Symfony: Override FOSUserBundle Resetting Controll

2019-08-23 12:33发布

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.

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.

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.

2条回答
孤傲高冷的网名
2楼-- · 2019-08-23 13:08

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 }

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. :)

查看更多
唯我独甜
3楼-- · 2019-08-23 13:11

Fix namespace from

namespace UserBundle\Controller\User;

to

namespace UserBundle\Controller;
查看更多
登录 后发表回答