您需要在模型中进行实体计算,由控制器启动,并将这些对象传递到视图中以推送到模板引擎中。
树枝看起来像这样:
{% for item in entity %}
{{ item.getSomething }}
{% for somevar in data %}
{{ somevar.getSomeOtherData }}
{% endfor %}
{% endfor %}
编辑:这是一个更精确的答案,您可以从这里推断:
// Controller
public function demoAction()
{
$demoModel = $this->get('demo.bundle.model.demo');
$demoView = $this->get('demo.bundle.view.demo');
$demoResult = $demoModel->myModelCalculation();
return $demoView->myDemoView($demoResult);
}
//Model
public function myModelCalculation()
{
return $this->getRepository('DataBundle:SomeData')->findAll();
}
//View
public function myDemoView($entity)
{
return $this->getTemplatingEngine()->renderResponse('DemoBundle:demo:index.html.twig', array('entity' => $entity));
}
//Twig
{% for item in entity %}
{{ item.getSomething }}
{% endfor %}
Symfony2 很容易学习,我建议学习他们的教程并阅读文档。
http://symfony.com/doc/current/index.html