0

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 ?

1
  • Show the entity class. Commented Nov 17, 2014 at 10:59

2 Answers 2

3

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.

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

2 Comments

Are you sure the result is an object of your Entity class, because that seems to be the problem. Could you just dump the result of that query and then paste it here?
That was an array of objects. I did a var_dump and found out. Problem Solved. Thank you for the previous answer
1

probably in twig :

{% for object in data %}

{{ object.id }}
{{ object.url }}

{% endfor %}

1 Comment

I want to process it specifically in php and then render the processed data in twig. Processing the data from the database is the actual logic.. For which I want to access the "links" individually

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.