How can I access the configuration of a Zend Framework application from a controller?

前端 未结 7 1647
忘掉有多难
忘掉有多难 2021-01-30 14:18

I have a Zend Framework application based on the quick-start setup.

I\'ve gotten the demos working and am now at the point of instantiating a new model class to do some

7条回答
  •  星月不相逢
    2021-01-30 15:02

    I always add the following init-method to my bootstrap to pass the configuration into the registry.

    protected function _initConfig()
    {
        $config = new Zend_Config($this->getOptions(), true);
        Zend_Registry::set('config', $config);
        return $config;
    }
    

    This will shorten your code a little bit:

    class My_UserController extends Zend_Controller_Action
    {
        public function indexAction()
        {
            $manager = new My_Model_Manager(Zend_Registry::get('config')->my);
            $this->view->items = $manager->getItems();
        }
    }
    

提交回复
热议问题