Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to add multiple parameters to route matching

I'm essentially trying to duplicate what happens when you use [] in a url, something like: page.php?type[]=1&type[]=2, etc.

Right now, I have this:

$routes->add("/read/(([0-9],?)+)", array(
  'controller'    => 'read',
  'action'        => 'index',
  'type'      => 1

Then I can explode the types on the ',', but that just seems clunky to me. Is there a better way to do this? I want users to be able to bookmark searches.


Why don't you use just same as ?type[]=1&type[]=2 ? Then it is not related with routing.

You can get them like below in controllers.


Yeah -- I suppose that would work -- just seems so inelegant when compared to the nice urls the rest of the app has :)

Thanks! -Seth

edited Jan '15

Well page.php?type[]=1&type[]=2 is sending query strings after the ? and you are using variables that are arrays at that point

brackets in a URL otherwise is non standard, ie page/type[]/type[] will break

if you are sending multiple types as "pretty url" you would send /page/1 AND/OR /page/1/2/3/4 and have to create a matching number

$routes->add("/page/([0-9]+)", array(
  'controller'    => 'page',
  'action'        => 'index',
  'type1'      => 1

$routes->add("/page/([0-9]+)/([0-9]+))/([0-9]+))/([0-9]+))", array(
  'controller'    => 'page',
  'action'        => 'index',
  'type1'      => 1,
  'type2'      => 2,
  'type3'      => 3,
  'type4'      => 4