Symfony 2 - When and why does a route parameter get automatically converted? -


i have route:

pfs_platform_home: path:      /{page}/{reset} defaults:  { _controller: pfsplatformbundle:advert:index, page: 1, reset: true } requirements:     page: \d*     reset: true|false 

if use link without specifying reset, router uses default value , in indexaction, reset parameter automatically converted boolean true. i.e.:

<li><a href="{{ path('pfs_platform_home') }}">inicio</a></li> 

but when that, time $reset appears string 'false' in indexaction, not boolean:

<a href="{{ path('pfs_platform_home', {'page': p, 'reset': 'false'}) }}">{{ p }}</a> 

what missing?

url paths , parameters strings. if have url like

http://example.com/page/true?foo=2&bar=false 

the server cannot know true should interpreted boolean, while foo supposed integer , bar supposed boolean, too.

if want process url parameters, pass , treat them strings.

later, can validate them (e.g. is_numeric tell if string represents number) or transform them other types.

what you're experiencing here yaml's handling of unquoted strings:

  • strings may left unquoted, if don't contain character has meaning in yaml.

  • but: true in yaml boolean true. therefore, default reset: true indeed boolean value. declare reset: "true" , should work. reset: true|false should fine, imo (didn't test it, treated regex, should interpreted string.)


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -