Re: Routing blues: routing / subcategory challenge
On Wed, Mar 13, 2013 at 2:41 PM, cyboman <allanmon@gmail.com> wrote:
> Hello fellow bakers,
>
> I've been trying to figure out a route challenge.
>
> I have the following routes which work fine:
>
> Router::connect('/category/*', array('controller' => 'categories', 'action'
> => 'index', 'category'));
> Router::connect('/subcategory/*', array('controller' => 'categories',
> 'action' => 'index', 'subcategory'));
Something like this could work. You may need to change the regex.
Router::connect(
'/category/:category',
// ...
array(
'category' => '[-a-z]+',
'pass' => array('category')
)
);
// put this before subcategory to make sure bare word 'item' is matched
Router::connect(
'/category/:category/item/:item',
// ...
array(
'category' => '[-a-z]+',
'item' => '[-a-z]+',
'pass' => array('category', 'item')
)
);
// anything except 'item'
Router::connect(
'/category/:category/:sub_category',
// ...
array(
'category' => '[-a-z]+',
'sub_category' => '[-a-z]+',
'pass' => array('category', 'sub_category')
)
);
Router::connect(
'/category/:category/:sub_category/item/:item',
// ...
array(
'category' => '[-a-z]+',
'sub_category' => '[-a-z]+',
'item' => '[-a-z]+',
'pass' => array('category', 'sub_category', 'item')
)
);
> As you can see, they pass a param of either 'category' or 'subcategory',
> this is used in the categories controller to change which model it searches
> from.
If you're switching models then it'd probably be better to create
routes for each. Probably controllers, too.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home