Symfony覆盖控制器和操作

时间:2016-02-05 13:58:53

标签: php symfony

我使用HWIO软件包并在我的自定义服务中抛出ConnectController中的公共函数connectServiceAction(Request $request, $service)后,在此操作中将我引发到HWIO模板,我知道如何重新加载模板但我不需要另外的模板我需要保留溃败:例子我在社交连接之后有路由“​​home_page”我想要仍然路由“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”但是如果我需要覆盖控制器另一个Bundle,那该怎么办?

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

1 个答案:

答案 0 :(得分:0)

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
  4. 一个例子:

    <?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>