Symfony重定向到服务逻辑之后的路由


Symfony redirect to a route after service logic

我从社交网络帮助中获取访问令牌,并在调用服务后重定向。我尝试将路由器添加到服务:

<argument type="service" id="router" />
use Symfony'Component'Routing'RouterInterface;
use Symfony'Component'Security'Core'User'UserInterface;
class UserProvider implements OAuthAwareUserProviderInterface
{
    protected $router;
    public function __construct(RouterInterface $router)
    {
        $this->router = $router;
    }
    public function connect(UserInterface $user, UserResponseInterface $response)
    {
        $service = $response->getResourceOwner()->getName();
        $serviceProvider = $service."Provider";
        $user = $this->$serviceProvider->setUserData($user, $response);
        $grabProject = $this->grabProject->grabProject($response->getAccessToken(), $user);
        return new RedirectResponse($this->router->generate('application_frontend_default_index'));
     }

在我的操作之后,我在连接服务操作中上交控制器 HWIO 捆绑包

public function connectServiceAction(Request $request, $service)
{

也许需要覆盖这个控制器和动作,怎么做?

控制器不会重定向,因为您在调用方法时没有return方法返回的RedirectResponse。如果您想快速修复以使其正常工作,只需替换:

$this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);

由:

return $this->container->get('hwi_oauth.account.connector')->connect($currentUser, $userInformation);

但是,正如我在评论中告诉您的那样:这不应该是您的服务重定向的责任。您应该在控制器中执行此操作,在connect调用之后立即执行此操作。