3

我得到的完整错误就是这个。

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".

这是处理动作的控制器:

 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]);
    }
}

和路由

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

Twig 和数据库,都是完全正常的,没有类型或问题。但是这个错误很难发现,我哪里出错了。

编辑:包括模板:

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

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

{% endblock %}

上面的模板位于views/article/它扩展了另一个模板中找到的views/ 只是

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

4

2 回答 2

3

FooBlogBundle:Article:articles.html.twig模板中你有类似的东西{{ path(FlickBlogBundle_articles) }}(不能确切地说,因为我没有看到模板)。这条路线需要额外的参数id。所以改成{{ path(FlickBlogBundle_articles, {'id':article.id}) }}

于 2013-08-10T16:27:44.387 回答
1

我遇到了同样的错误,在我的情况下,我忘记为我的私人外键设置公共 Getters 和 Setters:

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

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

/**
 * @param Provider $fkProvider
 */
public function setFkProvider($fkProvider)
{
    $this->fkProvider = $fkProvider;
}
于 2016-02-22T10:48:29.333 回答