2014-10-08 69 views
0

我有两个捆绑包A和B,在B中我需要重写A的模板,所以我使用了bundle inheritence。 目前为止一切正常,但现在我只需要在某些特定情况下覆盖包A的模板。我在包B的动作(将覆盖束A的动作)尝试这样做:在特定情况下覆盖模板和控制器

class ArticleController extends BaseArticleController 
{ 
    public function detailsAction(Request $request, $article) 
    { 
     if('general' === $article->getType()) { 
      // this doesn't return the template of the bundle A :(
      return parent::detailsAction($request, $article); 
     } 
     // else go on on rendering the other template... 
    } 

但这覆盖不管怎样,即使我的文章的类型是'general'它返回捆B的模板

回答

0

我已经找到了“错误”,我是不是desinging右整个压倒一切的事情:因为我重写A的控制器,这是完全没用为了覆盖树枝,所以我重新命名了捆绑树B的树枝ks就像一个魅力!

0

只是做这样的事情:

public function detailsAction(Request $request, $article) 
{ 
    if('general' === $article->getType()) { 
     // this doesn't return the template of the bundle A :(
     return parent::detailsAction($request, $article); 
    } 
    // else go on on rendering the other template... 

    return $this->render('YourBundleA:YourControllerA:YourTemplateA.html.twig', array(...)); 
} 
+0

这正是我所做的,但它是呈现B的模板,因为它具有与包A中相同的名称。我发布了我相信一个很好的解决方案 – smarber 2014-10-08 08:41:38