嵌入式控制器在树枝上

时间:2013-12-30 11:12:04

标签: symfony controller twig

大家好,这是我的掌握者:

   <?php

namespace ng\NearBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class WelcomeController extends Controller
{
  public function indexAction()
  {
   return $this->render('ngNearBundle:Welcome:index.html.twig', array('nom' => 'winzou'));
  }
  public function Header(){
  return $this->render('ngNearBundle:Welcome:nav.html.twig', array('nom' => 'winzou'));
  }
  public function Body(){
     return $this->render('ngNearBundle:Welcome:nav.html.twig', array('nom' => 'winzou'));
  }
}

这是索引树枝:

{# src/ng/NearBundle/Resources/views/Welcome/index.html.twig #}
{{ render(controller('ngNearBundle:Welcome:Header')) }}
{{ render(controller('ngNearBundle:Welcome:Body')) }}

我有这个错误:

An exception has been thrown during the rendering of a template ("The controller for URI "/_fragment" is not callable.") in ngNearBundle:Welcome:index.html.twig at line 2.

有谁知道原因以及我应该如何正确嵌入控制器?

2 个答案:

答案 0 :(得分:0)

Symfony2中控制器方法的约定规定,在方法名称的末尾有“Action”。

所以改变你的方法:

public function HeaderAction(){
     return $this->render('ngNearBundle:Welcome:nav.html.twig', array('nom' => 'winzou'));
}
public function BodyAction(){
     return $this->render('ngNearBundle:Welcome:nav.html.twig', array('nom' => 'winzou'));
}

你会得到理想的结果。

答案 1 :(得分:0)

并注意渲染,它使用了大量资源(内部就像一个新的请求),如果可能的话使用twig