This code dumps the correct $id
variable of type null
:
/**
* Show user
*
* @Route("/show/{id}", name="acme_user_show", defaults={"id"=null}, requirements={"id"="\d+"})
*/
public function showUserAction($id = null)
{
var_dump($id);
}
whereas the following code gives an $id
variable of type string
: string(4) "null"
/**
* Show user
*
*/
public function showUserAction($id = null)
{
var_dump($id);
}
routing.xml
<route id="acme_user_show" pattern="/show/{id}">
<default key="_controller">AcmeUserBundle:User:show</default>
<default key="id">null</default>
<requirement key="id">\d+</requirement>
</route>
I would assume the 2 to give similar results, is this normal? How would one give a default null value in xml?
/showUser
path to test if $id
variable is null.<default key="id" />
instead of <default key="id">null</default>
=> no successJust to clarify Patt's answer, this was fixed, the correct way to specify it is like this:
<default key="threadId" xsi:nil="true" />
So full route specification in your case would be like this:
<route id="acme_user_show" pattern="/show/{id}">
<default key="_controller">AcmeUserBundle:User:show</default>
<default key="id" xsi:nil="true" />
<requirement key="id">\d+</requirement>
</route>
This feature is not implemented in xml (yet). See this bug report.
@Aitboudad: The routing xml loader does not support null value, the correct way to represent null xml elements is xsi:nil="true".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With