views:

473

answers:

2

Hi you all:

I'm trying to capture a URL parameter in my bootstrap file but after several attempts I'm not able to do it.

I've tried this but it does not work:

protected function _initGetLang() {
  $frontController = Zend_Controller_Front::getInstance();
  $lang= $frontController->getParam('lang');
}

Is this the right way to do it?

Thks.

+4  A: 

You won't be able to access the request params from the bootstrap because it hasn't yet gone through the dispatch/routing process. I think you'd be better served by using a Controller Plugin; performing actions based on the URL is what they do best. Or if you absolutely have to do it in the bootstrap, getRequestUri() or $_GET is available, or you could write a quick script to parse the url yourself.

Edit:

I've done some silly stuff like this in the past before I figured out how plugins work:

/**
 * Grab the module name without a request instance
 *
 * @return string  The module name
 */
public static function getModuleName()
{
    $uri = ltrim($_SERVER["REQUEST_URI"], "/");
    $module = substr($uri, 0, strpos($uri, "/"));
    return $module;
}

This would at least give you a module name that you could switch on in the bootstrap. You should be able to do anything you need with the plugins done correctly though.

Typeoneerror
See also this Zend Devzone article: http://devzone.zend.com/article/3372
Ionuț G. Stan
Thank you guys for your answers, I tried the Plugin approach before but it didn't do what I wanted, nevertheless I'll read the article that 'lonut G. Stan' to check if I did something wrong, If that doesn't work, I'll do the $_GET thing that 'Typeoneerror' suggest.
elbicho
A: 

Hi,

Try this:

protected function _initGetLang() {
  $frontController = Zend_Controller_Front::getInstance();
  $lang= $frontController->getRequest()->getParam('lang');
}

regards