I am struggling with this detail while defining a route in Symfony2
Mi routing:
blog:
path: /blog/{page}
defaults: { _controller: ManualRouteBundle:Blog:show, page: 33 }
My controller:
<?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') ;
}
}
My view:
Blog # {{page}}
When I try to access with this address
http://test/web/blog
instead of
http://test/web/blog/1
I get this error
Variable "page" does not exist in ManualRouteBundle:Blog:show.html.twig at line 1
500 Internal Server Error - Twig_Error_Runtime
Isn't page value supposed to be 33?
I got the answer on #symfony, I have to pass the variable to the view.
$this->render() like this: $this->render('show.html.twig', array('page' => $page));
Weird behavior imho.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.