2016-02-05 39 views
0

我使用HWIO包,并且在我的自定义服务抛出ConnectController中的公共函数connectServiceAction(Request $request, $service)在此操作中将我引向HWIO模板,我知道如何重新加载模板,但我不需要另一个模板我需要停留从罗村:比如我有以后的社会路线“home_page”连我想还是击溃“home_page”Symfony覆盖控制器和操作

这是我的服务:

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

回答

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

举例:

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