Sf2.0, standard blog for example.
Code of routing.yml:
DevBlogBundle_post_show:
pattern: /posts/{id}
defaults: { _controller: "DevBlogBundle:Post:show" }
requirements:
_method: GET
id: \d+
Standard way i generate url for my post by using:
path('DevBlogBundle_post_show',{'id':post.id})
I use this constrution in all my temlates/layouts, which include posts list. An if i want to change my route for post_show (say... add Slug parameter /posts/{id}.{slug}), i will need to change all my temlates. Instead, i want to generate route by my Post model, something like:
public function getUrl(){
return $this->generator->generate('DevBlogBundle_post_show',array (...params...));}
Question: How can i get This Generator to my Post model, what i have to "use ..." and how to generate route?
In my templates i want to place:
<a href="{{ post.getUrl() }}" ...>...</a>
Thanks in advance.
{{ post|url }}
Have a read about extending twig here: kiwwito.com/article/… – Sgoettschkespath('DevBlogBundle_post_show',{'post':post})
orpath('DevBlogBundle_post_show',post)
and let the helper extract the necessary properties. But as it seems it is not possible... any ideas? – room13