2016-02-05 82 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>