-1

In my controller, I return the entity so that my twig template can use it like so:

return $this->render('review/index.html.twig',[
     "list" => $applications
]);

$applications is a query that returns the object I'm looking for:

$applications = $this->getDoctrine()->getRepository(ApplicationQueue::class)->findBy(
      array("assignment_mod_user" => $this->getUser()->getId())
);

And within my twig, I use the dump function to see if it's retrieving what I'm looking for. This is what is returned:

enter image description here

As you can see, there are two entities associated to this entity. In twig when I tired to do this, it failed to retrieve the data within:

{% for application in list %}
     {{application.application.[whateverhere]}}
{% endfor %}

How do I access the entities within an entity in twig when the data is already being pushed? The current output returns the error of:

Neither the property "application" nor one of the methods "application()", "getapplication()"/"isapplication()"/"hasapplication()" or "__call()" exist and have public access in class "App\Entity\ApplicationQueue".

Majo0od
  • 2,278
  • 10
  • 33
  • 58

2 Answers2

0

You have tu put double curly braces around your variable, like that :

{{ application.application.name }}

Look at the twig doc :

{% for user in users %}
    <li>{{ user.username|e }}</li>
{% endfor %}
0

You need to add an accessor to get the value of $application. This property is currently not accessible from outside the ApplicationQueue class.

class ApplicationQueue
{
    protected $application;

    public function getApplication(): CreatorApplication
    {
        return $this->application;
    }
}
G1.3
  • 1,693
  • 8
  • 24
  • 1
    Ok... so then what? How do you access that in twig? Do you need to call that function within twig, or pass it through the controller? A little more information could be helpful here. – Majo0od Apr 28 '20 at 19:01
  • Ok I understood, but might be worth to explain it. Each entity needs to have a function that retrieves the foreign entity, and within that foreign entity, there needs to be a function like `getUserName` to retrieve the data within twig. Then you can call that function within twig like so `application.application.user.getusername` – Majo0od Apr 28 '20 at 19:21