Symfony2 - Twig - 问题显示内容 [英] Symfony2 - Twig - Issue displaying content

查看:35
本文介绍了Symfony2 - Twig - 问题显示内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一些数据传递给我的模板.当我转储数据时,它看起来像这样

I pass some data to my template. When I dump the data it looks like so

array:2 [▼
  0 => array:4 [▼
    0 => AvailabilityAlert {#320 ▼
      -id: 34
      -searchCommand: "A01APRLONBAG"
      -isConnecting: "no"
      -lastUpdated: DateTime {#323 ▶}
      -isDeleted: false
      -alertStatus: "Active"
    }
    "classes" => "C,D"
    "flight_number" => "VS7"
  ]
  1 => ...

本质上,它是一个多维数组,但里面有一个对象(AvailabilityAlert)和一些其他数据.我正在尝试在我的模板中呈现这些数据.

Essentially, its a multi dimensional array, but inside there is an Object (AvailabilityAlert) and some other data. I am trying to render this data in my template.

获取要显示的附加数据(类、航班号)很容易

Getting the additional data (classes, flight_number) to display is easy

{% for alert in alerts %}
    {{  alert.classes }}
    {{  alert.pseudos }}
    {{  alert.flight_number }}
{% endfor %}

但是,我不确定如何显示对象数据.如果我尝试

However, I am not sure how to get the Objects data displaying. If I try

{% for alert in alerts %}

    {% for a in alert %}
        <tr>

            <td><a href="">{{ a.searchCommand }}</a></td>
             <td>{{ a.isConnecting }}</td>
             <td>{% if a.lastUpdated %}{{ a.lastUpdated|date('Y-m-d H:i:s') }}{% endif %}</td>
             <td>{{ a.isDeleted }}</td>
             <td>{{ a.alertStatus }}</td>
             <td>{{ a.id }}</td>
             <td>
                 <ul>
                     <li>
                         <a href="">show</a>
                     </li>
                 </ul>
             </td>
        </tr>
    {% endfor %}

    {{  alert.classes }}
    {{  alert.pseudos }}
    {{  alert.flight_number }}

{% endfor %}

我收到错误

无法访问字符串变量(C,D")上的属性(searchCommand")

Impossible to access an attribute ("searchCommand") on a string variable ("C,D")

那么我该如何显示这个对象呢?

So how would I display this Object as well?

推荐答案

尝试 alert[0].searchCommand 而不是 a.searchCommand,它应该有帮助 :) 那不需要嵌套循环.

Try alert[0].searchCommand instead of a.searchCommand, it should help :) That nested loop is not needed.

这篇关于Symfony2 - Twig - 问题显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆