lysitheas Posted October 16, 2010 Share Posted October 16, 2010 Hi, I've currently urls like http://example.com/index/index/lang/EN/content/5. I want to remove controller and action if they both are index, like http://example.com/lang/EN/content/5. To do that i overrided url view helper and if both controller and action are index removed them. In error controller i wrote: $front = Zend_Controller_Front::getInstance(); $router = $front->getRouter(); $request = $front->getRequest(); $response = $front->getResponse(); $current_controller = $request->getParam('controller'); $current_action = $request->getParam('action'); $request->setParams(array($current_controller=>$current_action,'controller'=>'index','action'=>'index')); Zend_Controller_Front::getInstance()->getDispatcher()->dispatch($request, $response); If a controller and action can't be found, simply it's redirecting to the index/index and i'm setting the undefined controller as a parameter which is 'lang' here. But the problem is however it is setting 'lang' as a parameter, after dispatching again it disappears. So my url turns to /index/index/content/5. Do you know any solution to that or do you have any other suggestions to remove default controller and actions from the url? Quote Link to comment https://forums.phpfreaks.com/topic/216008-zend-framework-removing-default-controller-and-action-from-url/ Share on other sites More sharing options...
ignace Posted October 16, 2010 Share Posted October 16, 2010 Add a custom route $router->addRoute( 'someroute', new Zend_Controller_Router_Route('lang/:lang/content/:content', array('controller' => 'index', 'action' => 'index')) ); $this->url(array('lang' => 'EN', 'content' => 5), 'someroute'); Quote Link to comment https://forums.phpfreaks.com/topic/216008-zend-framework-removing-default-controller-and-action-from-url/#findComment-1122745 Share on other sites More sharing options...
lysitheas Posted October 18, 2010 Author Share Posted October 18, 2010 Add a custom route Yeah, i know but the problem is users don't want to see lang parameter all the time. Only if language is changed except default and the only parameter that i'm worried is not lang, there are also a bunch of other parameters. I've started to write a plugin to check if controller exists but still i've concerns. Quote Link to comment https://forums.phpfreaks.com/topic/216008-zend-framework-removing-default-controller-and-action-from-url/#findComment-1123264 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.