Php 如何将getResult对象传递给Twig?
简单代码:Php 如何将getResult对象传递给Twig?,php,symfony,twig,Php,Symfony,Twig,简单代码: /** * @Route("/search") */ public function searchAction(Request $request) { $repository = $this->getDoctrine()->getRepository(Bike::class); $query = $repository->createQueryBuilder('b') ->where('b.brand >
/**
* @Route("/search")
*/
public function searchAction(Request $request) {
$repository = $this->getDoctrine()->getRepository(Bike::class);
$query = $repository->createQueryBuilder('b')
->where('b.brand >= :id')
->setParameter('id', '1')
->getQuery();
$result = $query->getResult());
我试过了
echo $result[0]['id'];
将数据保存到变量,但它提供:
Cannot use object of type AppBundle\Entity\Bike as array
在
var_dump($result[0]);
我有一些多维数组
object(AppBundle\Entity\Bike)[589]
private 'id' => int 1
private 'model' => string 'XXX' (length=9)
private 'material' => string 'BBB' (length=6)
我想将此数组或变量从数组传递到template.twig。您确实需要读取
您将找到解决方案,如下所示:
$this->render('default/index.html.twig', array(
'variable_name' => 'variable_value',
));
你真的需要读书
您将找到解决方案,如下所示:
$this->render('default/index.html.twig', array(
'variable_name' => 'variable_value',
));
现在在你看来:
{% for b in bike %}
{% if b.id >= 1 %}
// now put the names of attribs you need
{% endif %}
{% endfor %}
我希望这对你有帮助
现在在你看来:
{% for b in bike %}
{% if b.id >= 1 %}
// now put the names of attribs you need
{% endif %}
{% endfor %}
我希望这对你有帮助 您应该熟悉PHP的基础知识,比如访问对象properties@PatrickQ谢谢,物业助理帮助了我。:)为什么这里
->setParameter('id',1')
id是字符串?@ImanaliMamadiev我对代码做了一点修改,所以有一些口头错误。你应该熟悉PHP的基本知识,比如访问对象properties@PatrickQ谢谢,物业助理帮助了我。:)为什么这里->setParameter('id','1')
id是字符串?@ImanaliMamadiev我稍微修改了代码,所以有一些口头错误。