作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我得到的完整错误是这个。
在“FooBlogBundle:Article:articles.html”中呈现模板期间抛出异常(“缺少一些强制性参数(“id”)以生成路由“FooBlogBundle_articles”的 URL。”) .twig".
这是 Controller ,负责处理操作:
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' %}
最佳答案
在 FooBlogBundle:Article:articles.html.twig
模板中,您有类似 {{ path(FlickBlogBundle_articles) }}
的内容(无法准确判断,因为我没有看到一个模板)。此路由需要附加参数 id
。所以将其更改为 {{ path(FlickBlogBundle_articles, {'id':article.id}) }}
关于交响乐 3 : An exception has been thrown during the rendering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18163760/
我是一名优秀的程序员,十分优秀!