And*_*erj 15 url-routing symfony fosuserbundle
在用户使用FOSUserBundle的密码重置重置密码后,默认情况下,他被重定向到FOSUserProfile.我想重定向到另一条路线.这是可能的,如果可以,怎么样?
tom*_*rke 43
可以通过创建重置订户来完成:
namespace Acme\UserBundle\EventListener;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Event\FormEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
/**
* Listener responsible to change the redirection at the end of the password resetting
*/
class PasswordResettingListener implements EventSubscriberInterface {
private $router;
public function __construct(UrlGeneratorInterface $router) {
$this->router = $router;
}
public static function getSubscribedEvents() {
return [
FOSUserEvents::RESETTING_RESET_SUCCESS => 'onPasswordResettingSuccess',
];
}
public function onPasswordResettingSuccess(FormEvent $event) {
$url = $this->router->generate('homepage');
$event->setResponse(new RedirectResponse($url));
}
}
Run Code Online (Sandbox Code Playgroud)
然后将其注册为带有kernel.event_subscriber标记的服务:
# src/Acme/UserBundle/Resources/config/services.yml
services:
acme_user.password_resetting:
class: Acme\UserBundle\EventListener\PasswordResettingListener
arguments: [ @router ]
tags:
- { name: kernel.event_subscriber }
Run Code Online (Sandbox Code Playgroud)
小智 23
如果您没有使用FOS用户配置文件视图,则有一种丑陋但简单的方法:
加入你的app/config/routing.yml:
fos_user_profile_show:
path: /yourpath
Run Code Online (Sandbox Code Playgroud)