Symfony覆盖控制器和操作


Symfony overwrite controller and action

我使用 HWIO

捆绑包,在我的自定义服务在公共函数中抛出 ConnectController 后,connectServiceAction(Request $request, $service)在此操作中将我扔到 HWIO 模板,我知道如何重新加载模板,但我不需要另一个模板,我需要远离溃败:例如,我在社交连接后有路由"home_page",我仍然想要 rout "home_page"

这是我的服务:

class UserProvider implements OAuthAwareUserProviderInterface
{
    protected $grabProject;
    public function __construct(GgrabGithubProject $grabProject)
    {
        $this->grabProject = $grabProject;
    }
    /**
     * {@inheritDoc}
     */
    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);
    }
}  

在我的捆绑包中,我添加了

class MyBundle extends Bundle
{
    public function getParent()
    {
        return 'HWIOAuthBundle';
    }
}

并将 ConnectController 复制到我的目录中并更改逻辑而不是渲染模板,我将 redirest 添加到"home_page"中,但如果我需要覆盖控制器另一个捆绑包,该怎么办?

class MyBundle extends Bundle
{
    public function getParent()
    {
        return 'HWIOAuthBundle';//how to add another bundle ? 
    }
}
HWIOAuthBundle没有

ConnectController定义为服务,因此您基本上需要重新声明ConnectController硬编码的路由:

  1. https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/routing/login.xml
  2. https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/routing/redirect.xml
  3. https://github.com/hwi/HWIOAuthBundle/blob/master/Resources/config/routing/connect.xml

举个例子:

<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
    <route id="hwi_oauth_connect" path="/">
        <default key="_controller">YourCustomBundle:Connect:connect</default>
    </route>
</routes>