i new symfony2 , mvc in general. going through documentation symfony , in chapter on routing.
i getting confused annotation
/** * @route("/blog/{slug}", name="blog_show") */ public function showaction($slug) { // ... } i understand if user visits blog/xxx, showaction called. not understand why there name="blog_show" after comma in @route.
could please describe why use it?
is alias route
this name 1 have call example twig
<a href="{{ path('blog_show', {'slug': my-blog-post}) }}" ... it call /blog/my-blog-post
or if want redirect address
return new redirectresponse($this->generateurl('blog_show'), array('slug' => 'my-blog-post')); or generate url
$url = $this->generateurl('blog_show', array('slug' => 'my-blog-post')); here have documentation
http://symfony.com/doc/current/book/controller.html#redirecting
http://symfony.com/doc/current/book/templating.html#linking-to-pages
Comments
Post a Comment