brianlange Posted November 21, 2010 Share Posted November 21, 2010 I want to route everything to the index controller that is /action-name. How do I do this and still have /controller/action-name dispatch correctly? Also, I don't want to specify an action since I am using _call and render() in the controller . I am doing this because I have a lot of simple views and I don't want empty controller function. Thanks in advance. [ php]$route = new Zend_Controller_Router_Route_Regex( '(\w+)', array( 'controller' => 'index', 'action' => '' ));[/code] Quote Link to comment https://forums.phpfreaks.com/topic/219393-zf-routes/ Share on other sites More sharing options...
ignace Posted November 21, 2010 Share Posted November 21, 2010 Why do you need to have everything in the IndexController? If you create a controller for each of those you already have the desired result and closer to a correct implementation: class FooController extends Zend_Controller_Action { function indexAction() {} } class BarController extends Zend_Controller_Action { function indexAction() {} } domain.top/foo domain.top/bar Quote Link to comment https://forums.phpfreaks.com/topic/219393-zf-routes/#findComment-1137620 Share on other sites More sharing options...
brianlange Posted November 21, 2010 Author Share Posted November 21, 2010 I have dozens of view scripts that are basic html so I don't want to create empty controller functions and I definitely don't want to set up dozens of additional controllers with an empty index function. This route seems to do the trick. However the second one is necessary to make the home page / work. Is there a way to combine the two? $router->addRoute('pages', new Zend_Controller_Router_Route( '/:action', array('controller' => 'index', 'action' => ':action') ) ); $router->addRoute('index', new Zend_Controller_Router_Route( '/', array('controller' => 'index', 'action' => 'index') ) ); Quote Link to comment https://forums.phpfreaks.com/topic/219393-zf-routes/#findComment-1137624 Share on other sites More sharing options...
ignace Posted November 21, 2010 Share Posted November 21, 2010 Is there a way to combine the two? In your .htaccess create a 301 redirect from / to /index I'll have to see your full code of your IndexController and your Routes in order to be able to give you a different answer. Quote Link to comment https://forums.phpfreaks.com/topic/219393-zf-routes/#findComment-1137639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.