Hi, I thought of this but you then have to define for all the controllers you have and it could easily get out of control. However, till I get better advice, I have done the following. I had a problem only when the default action of the controller would be called. eg.
http://www.domain.com/help http://www.domain.com/contact http://www.domain.com/terms and so on. What I did is modify the routers.php so that before it outputs the controller and action based on the routes definied. I check if the route that I have defined to capture the city had incorrectly captured the controllers by doing: $controllerFilename = CONTROLLERS.$out['pass'][0].'_controller.php'; if (file_exists($controllerFilename)) { // Modify the output $out['controller'] = $out['pass'][0]; $out['action'] = 'index'; unset($out['pass']); } So essentially, what this would do is if the router incorrectly caught a valid controller then will route the path to correct controller. This does the job exactly as I want. But I would still want to hear better alternatives. Ketan Preloader wrote: > Hello Ketan, > > I'm not sure this is the best solution, but for me it works, if I > define all controller actions explicitly at the beginning: > > Router::connect('/', array('controller' => 'pages', 'action' => > 'display', 'home')); > Router::connect('/mycontroller1/:action', array('controller' => > 'mycontroller1')); > Router::connect('/mycontroller2/:action', array('controller' => > 'mycontroller2')); > > // all the others go to city > Router::connect('/*:action', array('controller' => 'city')); > > Hope this helps! > > Regards, Christoph > > On 31 Aug., 14:24, Ketan Patel <[EMAIL PROTECTED]> wrote: > > I want to create a url such as : > > > > http://www.domain.com/cityName -- Having issues with this as > > cityname could be any city in the world. > > > > http://www.domain.com/cityname/ab-12323-ksowld12aca2 -- Works fine. > > > > when I give the cityname, it goes on looking for > > 'CityNameController.php'. Now I can't go and create 100 controllers > > for 100 cities. There has to be a way to do it so that I can direct > > any cityname to a specific controller that takes care of all cities. > > > > The problem here is that if I want to assign special route for > > handling the citynames as below: > > > > Router::connect('/([A-z]+)', array('controller'=>'city', > > 'action'=>'show')); > > > > Now above will obviously capture all the controllers default action. > > ie. > > > > http://www.domain.com/helphttp://www.domain.com/contact_us > > > > I want to capture only city names and not other controllers. Is there > > a CAKE way to check if there is a valid controller then use that > > controller else forward to the city controller? > > > > I can code up in city controller that if it is not a valid city then > > do request action to the so-called controller. But I do not see this > > as a very good approach. Alternate way is to modify the router.php and > > check for controller's existence in there. > > > > Please let me know your views on how to approach this issue. > > > > Thanks, > > Ketan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
