0
votes

I'm building a web application and have been banging my head against a brick wall on a certain routing rule.

Here is the URL I am trying to achieve.

localhost/admin/location/123/pages/index

I am using the admin prefix which is working fine by uncommenting the following in app/config/core.php

Configure::write('Routing.prefixes', array('admin'));

'location/123' I want to essentially pass as parameters, so location with id of 123, 'pages' is the controller, 'edit' is the action.

There are other controllers that could replace 'pages' so this needs to be dynamic/wildcard. For example, a location could have pages, posts, users, etc.

Can anyone help me on how to write the Router::connect statement for this? Everything I try from the documentation doesn't seem to work.

Many thanks!

James

1

1 Answers

0
votes
Router::connect(
    '/admin/location/:location/:controller/:action/*', 
     array('admin' => 'true'),
     array('location' => '[0-9]+')
);

If you go to /admin/location/123/pages/display/home, for example, it will go to PagesController, display action and home parameter.

In $this->request->params, this route will send admin = true and location = 123