I am trying to route several different URLs to the same controller and function, but whichever I list as the second option in routes.php does not work.
Here is the code from routes.php:
Router::connect('/:city/locations/*', array('controller' => 'listings', 'action' => 'index_filter'), array('routeClass' => 'FilterRoute','pass' => array('city')));
Router::connect('/:city/cuisines/*', array('controller' => 'listings', 'action' => 'index_filter'), array('routeClass' => 'FilterRoute','pass' => array('city')));
The custom routeClass, 'FilterRoute' is as follows:
class FilterRoute extends CakeRoute {
function parse ( $url ) {
$params = CakeRoute::parse ( $url );
$filter_args = split ( "/" , substr($url,1) );
if ( count ( $filter_args ) < 1 ) {
return false;
}
$city = array_shift ( $filter_args );
$array_to_pass = array();
while ( count ( $filter_args ) > 1 ) {
$item1 = array_shift ( $filter_args);
$item2 = array_shift ( $filter_args );
$array_to_pass[ $item1 ] = $item2;
}
$params['pass'] = $array_to_pass;
return $params;
}
}
This class works fine and returns the expected array when I enter the first URL, but not for the second. I have reversed the order and again, it will work with the first URL, but not the second.
Any ideas how I can have them both working? I am trying to do it this way with the URL as the client does not want a word such as 'search' within the URL and we don't know which items will be listed as filter terms.
-- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment