0

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 => ...

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 %}

I get the error

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

So how would I display this Object as well?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.