Jump to content

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?

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.