Doctrine entity manager causing page to break

2020-04-14 08:41发布

问题:

I'm new to Symfony2 and trying to display a page listing items of an entity. However, once i use the code below the page breaks with a "No data received error" or "ERR_EMPTY_RESPONSE" leading me to think that my routes were not working and raising the issue here but the issue was related to Doctrine:

    public function indexAction() {
    $em = $this->getDoctrine()->getManager();

    $entities = $em->getRepository('ApsaBundle:Apsa')->findAll();

    return $this->render('ApsaBundle:Apsa:index.html.twig', array(
                'entities' => $entities,
    ));

However, this simple function displays the page :

    public function indexAction() {
             return $this->render('ApsaBundle:Apsa:index.html.twig');
   }

i'll be glad to know how to go about debugging this doctrine issue.Below the twig use to display the page

{% extends ::base.html.twig %}
{% block body -%}
    Apsa list

    <table class="records_list">
        <thead>
            <tr>
                <th>Id</th>
                <th>Titre</th>
                <th>Description</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
        {% for entity in entities %}
            <tr>
                <td><a href="#">{{ entity.id }}</a></td>
                <td>{{ entity.titre }}</td>
                <td>{{ entity.description }}</td>
                <td>
                <ul>
                    <li>
                        <a href="#">show</a>
                    </li>
                    <li>
                        <a href="#">edit</a>
                    </li>
                </ul>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

        <ul>
        <li>
            <a href="#">
                Create a new entry
            </a>
        </li>
    </ul>
    {% endblock %}

May you find the link to the zipped project here

回答1:

Probably due to a bad WAMP configuration.

I invite you to try with the build-in symfony server available by this command line:

php app/console server:run