samayo
samayo

Reputation: 16495

Symfony 3: An exception has been thrown during the rendering

The full error I am getting is this one.

An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("id") to generate a URL for route "FooBlogBundle_articles".") in "FooBlogBundle:Article:articles.html.twig".

This is the controller, that handles the action:

 public function articlesAction($id)
    {
        $em = $this->getDoctrine()->getManager();
            $blog = $em->getRepository('FooBlogBundle:Blog')->find($id);

        if(!$em){
            throw $this->createNotFoundException('Unable to find blog posti');
        }

        return $this->render('FooBlogBundle:Article:articles.html.twig', ['blog'=>$blog]);
    }
}

and the routing

FlickBlogBundle_articles:
    pattern:  /foo/{id}
    defaults: { _controller: FooBlogBundle:Article:articles }
    requirements:
      _method: GET
      id: \d+

Twig and database, are completely normal, no type or problems. But this error is kind of hard to spot, where I have gone wrong.

EDIT: Including template:

{% extends 'FooBlogBundle::layout.html.twig' %}

{% block body %}
{{ blog.title }}<br/>
{{ blog.author }}<br/>
{{ blog.blog }}<br/>
{{ blog.tags }}<br/>
{{ blog.comments }}

{% endblock %}

The above template is located in views/article/ it extends another templates found at views/ whic is just

{% extends 'FooBlogBundle::layout.html.twig' %}

Upvotes: 3

Views: 7357

Answers (2)

Santi Iglesias
Santi Iglesias

Reputation: 464

I got the same error and in my case I forgot to set public Getters & Setters for my private foreign Key:

/**
 * @var Provider
 *
 * @ORM\ManyToOne(targetEntity="Provider")
 * @ORM\JoinColumn(name="fk_provider", referencedColumnName="id", nullable=true)
 */
private $fkProvider;

And

/**
 * @return Provider
 */
public function getFkProvider()
{
    return $this->fkProvider;
}

/**
 * @param Provider $fkProvider
 */
public function setFkProvider($fkProvider)
{
    $this->fkProvider = $fkProvider;
}

Upvotes: 1

Alexey B.
Alexey B.

Reputation: 12033

In FooBlogBundle:Article:articles.html.twig template you have something like {{ path(FlickBlogBundle_articles) }} (can not tell exactly because I do not see a template). This route requires additional parameter id. So change it to {{ path(FlickBlogBundle_articles, {'id':article.id}) }}

Upvotes: 3

Related Questions