Reputation: 347
I've used the following in my Controller Action
$data = $this->getDoctrine()->getRepository('MyBundle:links')->findAll();
data now holds and array of objects of class "Links" which are as follows
Array
(
[0] => MyBundle\Entity\links Object
(
[id:MyBundle\Entity\links:private] => 2
[urls:MyCheckerBundle\Entity\links:private] => http://localhost/1.php
)
[1] => MyBundle\Entity\links Object
(
[id:MyBundle\Entity\links:private] => 1
[urls:MyCheckerBundle\Entity\links:private] => http://localhost/2.php
))
How do I process this array of objects if I want to access id and urls so that I can display on my page ?
Upvotes: 0
Views: 509
Reputation: 329
The array is just an array containing the entities of yours.
So what you can do is this:
foreach ($data as $object) {
// ID variable
var id = $object->getId()
var urls = $object->getUrls() // Not sure if the method is called.
What it comes down to; you can just use the methods you have defined in your entities to access the properties of those objects.
Upvotes: 3
Reputation: 634
probably in twig :
{% for object in data %}
{{ object.id }}
{{ object.url }}
{% endfor %}
Upvotes: 1