douyou2732 2013-06-18 17:46
浏览 24
已采纳

使用twig传递值时出现Symblog错误

I'm following the symblog tutorial right now, using Symfony 2.2.2

2.3 has some breaking changes, so I'm using 2.2 to get info on deprecated functions. But to the problem:

After having created the comment form, I got an error saying no route was found for the GET comment:new controller.

That appeared to be an update in Twig, where the following code used to work:

{% render 'BloggerBlogBundle:Comment:new' with { 'blog_id': blog.id } %}

You must now use:

{% render controller('BloggerBlogBundle:Comment:new') with { 'blog_id': blog.id } %}

After that, I got another error, stating the following:

Controller "Blogger\BlogBundle\Controller\CommentController::newAction()" requires that you provide a value for the "$blog_id" argument (because there is no default value or because there is a non optional argument after this one).

As far as I'm aware, with { 'blog_id': blog.id } should pass that argument along. But it's not.

The comments for the tutorial are extensive, but nothing mentions this. And I'm not very familiar with twig and symfony, I don't know where else to look for the problem.

EDIT: to be clear, I am calling this controller function from within an already existing twig file, not from inside a PHP file. No route has been defined for it. The action will then call another twig file to include the form element to the page. The tutorial explains this is so the form can be re-used on various parts of the site, removing the need to make a large amount of form elements which basically all do the same thing.

  • 写回答

2条回答 默认 最新

  • douhu2898 2013-06-18 17:51
    关注

    according to the symfony documentation you should use

    {{ render(controller('BloggerBlogBundle:Comment:new', { 'blog_id': blog.id })) }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗