<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ParamConverter | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/paramconverter/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Mon, 15 Dec 2014 13:07:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Symfony and named ParamConverters</title>
		<link>https://nerdpress.org/2014/12/15/symfony-named-paramconverters/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Mon, 15 Dec 2014 13:07:36 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[ParamConverter]]></category>
		<category><![CDATA[Symfony2]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=2591</guid>

					<description><![CDATA[<p>Symfony&#8217;s ParamConverter is a common way to transform some GET param to an entity before your controllers action. This happens most of the time via type hinting and priority detection kinda magic in the background. But as magic is often obscure sometimes you need a bit of explicitness. F.e. when you have more and different &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2014/12/15/symfony-named-paramconverters/" class="more-link">Continue reading<span class="screen-reader-text"> "Symfony and named ParamConverters"</span></a></p>
The post <a href="https://nerdpress.org/2014/12/15/symfony-named-paramconverters/">Symfony and named ParamConverters</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>Symfony&#8217;s ParamConverter is a common way to transform some GET param to an entity before your controllers action.<br />
This happens most of the time via type hinting and priority detection kinda magic in the background.<br />
But as magic is often obscure sometimes you need a bit of explicitness.</p>
<p>F.e. when you have more and different ParamConverter per entity you want to name them explicitly.<br />
Then you can use named ParamConverters.</p>
<p>In the documentation this issue is a bit fragmented, so here is the compact version:<br />
<span id="more-2591"></span></p>
<p><strong>Declare:</strong><br />
Set the &#8220;converter&#8221; attribute in the param_converter service tag.<br />
Read it in the documentation: <a href="http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#creating-a-converter" target="_blank">http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#creating-a-converter</a></p>
<p><em>You can register a converter by priority, by name (attribute &#8220;converter&#8221;) or both.</em></p>
<pre class="brush: xml; title: ; notranslate">
&lt;service id=&quot;my_converter&quot; class=&quot;MyBundle\Request\ParamConverter\MyConverter&quot;&gt;
    &lt;tag name=&quot;request.param_converter&quot; priority=&quot;-2&quot; converter=&quot;my_converter&quot; /&gt;
&lt;/service&gt;
</pre>
<p><strong>Use:</strong><br />
In you controller annotation call the ParamConverter with the converter attribute.<br />
The Symfony <a href="http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html" target="_blank">ParamConverter dokumentation</a> explains it like this:<br />
<em>If an explicit converter choice was made with @ParamConverter(converter=&#8221;name&#8221;) the converter with the given name is chosen.</em></p>
<pre class="brush: php; title: ; notranslate">use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

/**
 * @ParamConverter(&quot;post&quot;, converter=&quot;my_converter&quot;)
 */
public function showAction(Post $post)
{
}</pre>The post <a href="https://nerdpress.org/2014/12/15/symfony-named-paramconverters/">Symfony and named ParamConverters</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
