<p dir="auto">When generating URLs, named parameters are usually passed like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$uri = $router-&gt;generate('blog_show', array('slug' =&gt; 'my-blog-post'));"><pre class="notranslate"><code class="notranslate">$uri = $router-&gt;generate('blog_show', array('slug' =&gt; 'my-blog-post'));
</code></pre></div>
<p dir="auto">It would be cool if one could pass an object that implements the <code class="notranslate">ArrayAccess</code> interface, too. That would make generating routes for models incredibly easy (and allow for changing the URL parameters without changing the places where the URLs are generated).</p>
<p dir="auto">Something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$uri = $router-&gt;generate('blog_show', $post);"><pre class="notranslate"><code class="notranslate">$uri = $router-&gt;generate('blog_show', $post);
</code></pre></div>
<p dir="auto">Quite possibly the current implementation loops through the array and then tries to replace the appropriate placeholder if it exists. For this to work, that implementation would obviously have to be reversed - take the route, search for placeholders and then look for the corresponding parameters.</p>
<hr>
<p dir="auto">Not sure, maybe this is already possible, I wasn't very successful digging through the code.</p>
<p dir="auto">For Symfony2 Router with the help of standart bundle (sensio extra) we can write ParamConverters to convert request param=&gt;object. Is there any standart way to use reversed convertion?</p>
<p dir="auto">Now we must do something like this:<br>
path('DevBlogBundle_post_show',{'post':post.id})<br>
While a better way would be:<br>
path('DevBlogBundle_post_show',{'post':post})</p>
<p dir="auto">I've found even example jist:<br>
<a href="https://gist.github.com/stevelacey/3226510">https://gist.github.com/stevelacey/3226510</a></p>
<ol dir="auto">
<li>Maybe, we should think about adding such functionality to future releases of, for example, sensioFrameworkExtra bundle?</li>
<li>If there is no such functionality, is bundle providing such extension would be needed?</li>
</ol>
<p dir="auto">Thanks.</p>