How to access URL parameters in bootstrap
Asked Answered
N

1

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.

Noodle answered 20/10, 2009 at 9:27 Comment(0)
T
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.

Trilley answered 20/10, 2009 at 11:31 Comment(1)
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.Noodle

© 2022 - 2024 — McMap. All rights reserved.