I'm experimenting with SEO friendly URL's in CakePHP as efficiently as I can, I've managed to use the current format, each example uses function view($slug) except for the first example which uses function index().
/categories/
/categories/books/
/categories/books/it-and-comput开发者_JAVA技巧ing/
But what if IT & Computing has a sub-category "Web Development"? I'd like the URL to become:
/categories/books/it-and-computing/web-development/
I'm not sure how to do this without creating too many routes. Here is my route code so far:
Router::connect('/categories/', array('controller' => 'categories', 'action' => 'index'));
Router::connect('/categories/:slug', array('controller' => 'categories', 'action' => 'view'), array('pass' => array('slug')) );
Router::connect('/categories/:parent/:slug', array('controller' => 'categories', 'action' => 'view'), array('pass' => array('parent', 'slug')) );
Any help would be greatly appreciated
Kind Regards
Stephen
// in routes.php
Router::connect('/categories/:row:lastslash',array('controller' => 'settings', 'action' => 'show',),array(
'pass'=>array('row'),
'row'=>'.*?',
'lastslash'=>'\/?'
));
//in controller
function show($row = ""){
if($row){
$categories = split('/',$row);
?><pre><? print_r($categories);?></pre><?die();
}else{
die('do something else');
}
}
/categories/books/computing/web-development/cakephp/
result:
Array
(
[0] => books
[1] => computing
[2] => web-development
[3] => cakephp
)
/categories/
result:
do something else
/categories/books
result:
Array
(
[0] => books
)
精彩评论