首页 文章

重写捆绑模板“资源被资源隐藏”时Symfony2错误?

提问于
浏览
1

我'm trying to override a third party bundle'的布局模板与我的包的布局,通过在app / Resources /目录中包含新的布局,如Symfony2 book section所示;但是,我得到以下异常:

“... path_to_my_app / app / Resources / FOSUserBundle / views / layout.html.twig”资源被“MyVendorMyBundle”派生包中的资源隐藏 . 创建“... path_to_my_app / app / Resources / MyVendorMyBundle / views / layout.html.twig”文件以覆盖包资源 .

特别是,我想用我的包中的那个覆盖FOSUserBundle布局 . 我按照bundle's documentation中显示的步骤进行操作,这与Symfony书中的步骤没有什么不同 .

What could be the cause of this exception? and how can I make it work?

我尝试将我的bundle的布局放在app / Resources / MyVendorMyBundle / views /中,如上面的异常消息中所示,但如果我这样做,则只读取并返回MyBundle的布局,而不是扩展它的FOSUserBundle的模板 .

1 回答

  • 3

    事实证明,在我之前的开发人员将MyBundle设置为FOSUserBundle的子项为shown in the documentation(没有我注意到......):

    // src/Acme/UserBundle/AcmeUserBundle.php
    namespace Acme\UserBundle;
    use Symfony\Component\HttpKernel\Bundle\Bundle;
    
    class AcmeUserBundle extends Bundle
    {
        public function getParent()
        {
            return 'FOSUserBundle';
        }
    }
    

    上面显然与app / Resources / FOSUserBundle / views /文件夹中的(隐藏)重新定义的布局模板产生冲突 . 我刚刚从上面显示的bundle类中删除了getParent()方法来解决问题 .

相关问题