【问题标题】:Symfony overwrite controller and actionSymfony 覆盖控制器和动作
【发布时间】:2016-02-08 07:33:32
【问题描述】:

我使用 HWIO 捆绑包,在我的自定义服务在公共函数 connectServiceAction(Request $request, $service) 中的 ConnectController 中引发此操作后,我将进入 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 ? 
    }
}

【问题讨论】:

    标签: php symfony


    【解决方案1】:

    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>
    

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      相关资源
      最近更新 更多