2016-09-24 72 views
1

我遇到了一個symfony exeption和一些參數我試圖得到一個麻煩。我完全不知道爲什麼我經過數千次我的代碼檢查以及在互聯網上後纔得到這個異常。Symfony2.7:小枝渲染控制器()忽略我的參數

唯一的例外是:模板的渲染(「‘「一些強制性的參數丟失(」塞’)來生成路由URL」 blogcomment_create)期間

異常被拋出@Blog \ DEFAULT \在行博客\ singlePost.html.twig 29

路由配置:

blogcomment_create: 
    path: /{slug}/comment/create/ 
    defaults: { _controller: "BlogBundle:Comment:create" } 
    requirements: { methods: post } 

我在我的樹枝模板代碼導入我的控制器:

<footer> 
    {{ render(controller('BlogBundle:Comment:create', { 
     'slug': Post.slugname 
    })) }} 
</footer> 

我的行動聲明:

public function createAction(Request $request, $slug = null) 
{ 
    //... 
} 

我開始生氣與此異常,我沒有線索,爲什麼我得到了她,我真的需要一雙好眼睛。

我嘗試exemples噸:

How to insert a Controller in Twig with "render" in Symfony 2.2?

symfony2 - twig - how to render a twig template from inside a twig template

Change template via parameter when render a controller action?

...

這裏fonction的轉儲:

object(Symfony\Component\HttpKernel\Controller\ControllerReference)[992] 
    public 'controller' => 
     string 'BlogBundle:Comment:create' (length=31) 
    public 'attributes' => 
     array (size=1) 
      'slug' => string 'article-de-test-yolowowo' (length=24) 
    public 'query' => 
     array (size=0) 
      empty 

回答

0

好吧,我最終得到它!

這個問題根本不在我的樹枝模板中,而是在我的控制器中。我有一個功能來在這個控制器中生成我的表單。我叫她在我的行動:

private function createCreateForm(Comment $entity, $slug) 
{ 
    $form = $this->createForm(new CommentType(), $entity, array(
     'action' => $this->generateUrl('blogcomment_create', array('slug' => $slug)), 
     'method' => 'POST', 
    )); 

    $form->add('submit', 'submit', array('label' => 'Create')); 

    return $form; 
} 

在這個功能我忘了傳遞這個fonction參數:

$this->generateUrl() 

我真正需要的時候,我得到那樣的問題入睡越快>>

我希望我的問題將在未來幫助其他人。