7

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.

elbicho
  • 365
  • 1
  • 3
  • 12

1 Answers1

9

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.

Adeel
  • 2,901
  • 7
  • 24
  • 34
typeoneerror
  • 55,990
  • 32
  • 132
  • 223
  • 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 Oct 20 '09 at 14:12