[英]Symfony2 Optional parameter in routing has no value
在Symfony2中定义路线时,我在这个细节上苦苦挣扎
小米路由:
blog:
path: /blog/{page}
defaults: { _controller: ManualRouteBundle:Blog:show, page: 33 }
我的控制器:
<?php
namespace Manual\RouteBundle\Controller ;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class BlogController extends Controller{
public function showAction($page){
return $this->render('ManualRouteBundle:Blog:show.html.twig') ;
}
}
我的观点:
Blog # {{page}}
当我尝试使用该地址访问时
http://test/web/blog
代替
http://test/web/blog/1
我得到这个错误
Variable "page" does not exist in ManualRouteBundle:Blog:show.html.twig at line 1
500 Internal Server Error - Twig_Error_Runtime
页面值不应该是33吗?
我得到了#symfony的答案,我必须将变量传递给视图。
$this->render() like this: $this->render('show.html.twig', array('page' => $page));
怪异的行为恕我直言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.