I have a method in my users controller similar to:

function members($type = null, $category = null) { ... }

Both params are optional and can be used together or on their own.

So with the following route.

Router::connect('/members/*', array('controller' => 'users', 'action' => 'members')); successfully becomes

Unfortunately the following don't work

how could I set up my routes so that they all work properly?

Was it helpful?


Named parameters aren't automagicaly mapped to the action. You can either get them by calling

$this->passedArgs['type'] or $this->passedArgs['category']

or by using the 3rd parameter in the Router::connect:

    array('controller' => 'users', 'action' => 'members'),
        'pass' => array('type', 'category')


Try with

Router::connect('/members/type\:(.*)', array('controller' => 'users', 'action' => 'members_type'));
Router::connect('/members/category\:(.*)', array('controller' => 'users', 'action' => 'members_category'));
Router::connect('/members/type\:(.*)/category:(.*)', array('controller' => 'users', 'action' => 'members_type'));

Note that I didn't test it, but I think you must escape the colon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow