3

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.

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

An URL with an array will look like this: http://domain.com?array[]=lorem&array[]=ipsum
@user2019515 true, but I'm not sure that symfony2 allows that
1

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.

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.