Php symfony中的getContainer

Php symfony中的getContainer,php,symfony,Php,Symfony,我正在尝试从细枝模板获取块,然后将其渲染到我的索引模板: {% block round1 %} <h1> hello this is a sample for a round 1</h1> {% endblock %} {% block round2 %} <h1> hello this is a sample for a round 1</h1> {% endblock %} 然后在我的索引模板中使用它 {{dynamic}} 但是我有个问

我正在尝试从细枝模板获取块,然后将其渲染到我的索引模板:

{% block round1 %}
<h1> hello this is a sample for a round 1</h1>
{% endblock %}

{% block round2 %}
<h1> hello this is a sample for a round 1</h1>
{% endblock %}
然后在我的索引模板中使用它

{{dynamic}}
但是我有个问题,symfony说

FatalErrorException: Error: Call to undefined method 
Alvin\MainBundle\Controller\IndexController::getContainer() in /Users/alvinvaldez/Sites/alvinwebsite/src/Alvin/MainBundle/Controller/IndexController.php line 26

我不知道如何使容器运行。

控制器没有
getContainer()
方法

您可以通过
$this->container
直接访问它,就像
$this->container->get('twig')


但是Symfony为控制器提供了快捷方式方法,您也可以使用
$this->get('twig')

是的,但是出现了一个新的问题:传递给twig_Template::renderBlock()的参数2必须是数组类型,Aoi Yes,应该提供一个数组作为参数;但在我的索引模板中,动态结果是这样的:“您好,这是第一轮的一个样本”我找到了一个答案{{dynamic | raw}
FatalErrorException: Error: Call to undefined method 
Alvin\MainBundle\Controller\IndexController::getContainer() in /Users/alvinvaldez/Sites/alvinwebsite/src/Alvin/MainBundle/Controller/IndexController.php line 26