Reputation: 450
I want to create a route, that matches on an array.
example:
Name_show: pattern: /Name/{names} defaults: { _controller: testBundle:Name:showNames }
where {names}
holds an array of names, like:
array([1] => 'Thomas', [2] => 'Anton', [3] => 'Berta');
How to handle this? Symfony 2.0 responses with
Warning: preg_match() expects parameter 2 to be string, array given
can't find any solution in symfony doc.
Upvotes: 3
Views: 8030
Reputation: 25
I agree with @JamesHalsall about serializing. I would also add that the serialized string should then be urlencoded before being used as a GET parameter.
Upvotes: 1
Reputation: 995
You have to validate the route, so either use some contrived event handling (see the kernel.controller event ) or use a controller that simply redirects to a new URL if the Name is in the array or displays an error page.
Also you could experiment with the ChainRouter that is a replacement for the default Symfony2 router (supports Doctrine-based routing and such).
Upvotes: 0
Reputation: 13475
You can use it as a string and just serialize()
the content before and after.
As far as I know symfony2 doesn't allow arrays in routing, how would the URL Look with an array in? A URL has to be a string, so serializing the array and passing it as a string is probably a better option.
Upvotes: 3