I'm using Zend Framework 1.8/1.9's Zend_Application
and the resource system to initilize a bunch of resources. I would like to only load certain .ini files based on the module being requested – for example, loading "help.ini" if (and only if) the CMS module is requested ("/cms"). Trouble is, I'm not sure how to access the request object in a Zend_Application_Resource_ResourceAbstract
subclass.
In one of my resources (for initializing custom routes for the CMS), I use a hacky little util to get the module (below), and then I add custom routes if it matching the "cms" module name:
/**
* 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;
}
$module = Typeoneerror_Util_Strings::getModuleName();
// -- only attach certain routes if using cms module
if ($module == Typeoneerror_Constants::CMS_MODULE)
{
...
I'd like this to be more "Zend-y", i.e. like a controller plugin, where a request object is passed to the class:
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$router = $this->__front->getRouter();
...
Any ideas?