suggestions though
** If you can guarantee that all of your product slugs will have at
least one hyphen then you can do this:
Router::connect('/products/([a-z0-9_](-[a-z0-9_])+)/([0-9]+)' =>
array(...)
Because actions can't have hyphens in them, for obvious reasons.
** If the other actions will be hidden from the vast majority of
users, it might make sense to create a totally different prefix:
Router::connect('/catalogue/*/([0-9].*)', array('controller' =>
'products', 'action' => 'view'));
This will make /catalogue/this-is-a-product/101 work, and will not
affect product actions because they'll be accessed through /
products/../...
** If you reverse the order of the slug and id then you'll be fine,
because actions can't be all numeric:
Router::connect('/products/([0-9]+)/*' => array('controller' =>
'products', 'action' => 'view'))
(This will make /products/101/this-is-a-product work fine)
** If all that fails, you could re-dispatch in your view action:
function view($slug, $id = null) {
if (method_exists($this, $slug) && $slug[0] != '_') {
$args = func_get_args();
return $this->dispatchMethod('setAction', $args);
}
// .. Handle view action normally
}
Although this might well mess up any beforeFilter() callbacks and
whatnot. Experimentation is needed...
hth
grigri
On Sep 16, 6:48 am, benko <mike.benkov...@gmail.com> wrote:
> Hey Guys,
>
> I am creating a new system with a large collection of products. The
> URLs currently work like this
>
> /products/view/this-is-a-product/101
>
> Everything works fine but I would like the URLs to be of the form:
>
> /products/this-is-a-product/101
>
> I have added this to the Router:
>
> Router::connect('/products/*/([0-9].*)', array('controller' =>
> 'products', 'action' => 'view'));
>
> This works just fine but the issue is I have several other actions in
> the products controller and all these are being caught by the * in the
> route. So things like /products/add/101 are being routed to the view
> action.
>
> Does anyone know of a way to fix this without explicitly excluding all
> of my current actions. Id like to be able to add new actions to my
> controller without having to change the routing.
>
> Any help would be much appreciated.
> Long Live CakePHP :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment