【发布时间】:2015-07-08 13:58:20
【问题描述】:
我在控制器中编写了一个动作。我想将“结果”数组传递给树枝文件,并且还想通过 for 循环使用它。
这是我在控制器中的操作代码
public function searchBookAction(Request $request)
{
$q="PC";
$conn = $this->get('database_connection');
$results = $conn->fetchAll("SELECT name FROM products where name like '%".$q."%'");
return array('results' => $results);
}
这是我的树枝代码:
{%for data in results%}
<li>{{ data.name|e }}</li>
{% endfor %}
</ul>
在此代码中,我收到此错误: NimoProBundle:Product:product.html.twig 中不存在变量“结果”
【问题讨论】:
标签: php symfony symfony-2.6