Jump to content

Archived

This topic is now archived and is closed to further replies.

lysitheas

Zend Framework removing default controller and action from url

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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');

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.