0

Controller code:

    $em = $this->getEntityManager();

    $books = $em->getRepository('Books\Model\Books')->findAll();

    return $this->render('Books/View/list.html.twig', array(
        'books' => $books
    ));

Twig template code:

{% extends 'Books/View/layout.html.twig' %}

{% block content %}
<table>
   <tr>
        <th>Name</th>
        <th>Description</th>
   </tr>
   {% for row in books %}
       <tr>
           <td>{{ row.name }}</td>
           <td>{{ row.description }}</td>
       </tr>
   {% endfor %}
</table>
{% endblock %}

I don't know why I don't see nothing in cell's designed for name and description. When I open developer console and look into html tree I see this cell's but empty..

2
  • When I open developer console and look into html tree I see this cell's but empty.. - I mean: I see 'td' tags but without data Commented Mar 24, 2016 at 21:11
  • 1
    I think the fact that you see tds implies that the query was successful and it is actually iterating over books. Are you sure the property names are correct? I would try dumping books to verify what's really there. Commented Mar 24, 2016 at 21:23

1 Answer 1

1

As far as I remember You need to create getters:

class Books
{
    /** @Id @Column(type="integer") @GeneratedValue */
    private $id;

    /** @Column(type="string") */
    private $name;

    /** @Column(type="string") */
    private $description;

    public function getName() { return $this->name; }
    public function getDescription() { return $this->description; }
}

Just read manual 7. Working with Objects

You might prefer to read markdown documentation Doctrine1 Documentation. I am writing md files myself so prefer to read them too.

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.