简体   繁体   中英

Zend application.ini resourse for different modules

I am writing a zend application and trying to keep the functionality as modular as possible. Basically I want to drop the folder into the application and have instant functionality.

Anywho; I'm trying to create sidebar links from each module. The method I'm using is to use the bootstrap:

Here is the function in my bootstrap file. I've set the routes in another function.

 public function _initNavigation()
 {
  $navigation = new Zend_Navigation();
  $navigation->addPages(
      array(
        array(
          'label' => 'Link Name',
          'route' => 'routeA',
          'class' => 'heading'
        ),
        array(
          'label' => 'Link Name',
          'route' => 'routeA',
          'params'=>array('param' => 'value'),
        ),
        array(
          'label' => 'Link Name',
          'params'=>array('param' => 'value'),
          'route' => 'routeA'
        )
      )
  );

  $this->bootstrap('layout'); //this line giving error :(
  $layout = $this->getResource('layout');
  $view = $layout->getView();
  $view->navigation($navigation);

The error I was getting was:

Resource matching "layout" not found

After some head banging I found that I had to put the module name in front of the resourse in the config/application.ini file, eg:

moduleA.resources.layout.layoutPath = APPLICATION_PATH "/modules/moduleA/views/scripts"

Now here's the question: how do I get the layout resource using a single resource? ie without specifying the module name for each new module I use?

Made answer new post


After a LOT of googling (when did THAT become a replacement for 'searching'?) I came across Leonard Dronkers' "Zend Framework Module Config The Easy Way" .

Basically, add this to your module's bootstrap file

/**
 * Load config.ini file for this module.
 */
protected function _initModuleConfig()
{
    // load ini file
    $iniOptions = new Zend_Config_Ini(dirname(__FILE__) . '/configs/config.ini');

    // Set this bootstrap options
    $this->setOptions($iniOptions->toArray());
}

And place a config.ini file in a config folder in your module (eg /modules/news/config/config.ini) and place your module specific settings there.

That's it. Fantastic!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM