Zend config.ini从脚本中引用的参数


Zend config.ini parameters referred from a script

Zend框架谈话。我知道:

"When referring to configuration parameters within a script,
 you'll prefix it with $this->config and converting the periods 
 to right-facing arrows"

问题:但是,当我尝试回显"$this->config->website->url;"时我没有输出。

如果我尝试使用"$this->config[website][url]",我会收到正确的输出。

我错在哪里?

我有:

我的引导类

[..]
    protected function _initConfig() 
{     
    $config =$this->getOptions();// contents of config file
    Zend_Registry::set('config', $config);     
    return $config; 
}   
protected function _initAction()
{
    Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH."'My'Helper",'My_Action_Helper');
    Zend_Controller_Action_HelperBroker::getStaticHelper('Initializer');

}

My_Action_Helper_Initializer

class My_Action_Helper_Initializer extends Zend_Controller_Action_Helper_Abstract
{
 public function init()
 {
    $controller=$this->getActionController();
    $controller->config=Zend_registry::get('config');
 }  
}

我的索引控制器

class IndexController extends Zend_Controller_Action
{
 public function indexAction()
 {
  echo $this->config[website][url];//it outputs the correct value
  echo $this->config->website->url;//NO OUTPUT!  
 }
}

谢谢

卢卡

试一试:)

启动:

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

以及您想在哪里使用它:

$config = Zend_Registry::get('config');

您将数组存储在选项而不是对象中 (Zend_Config)

使用

 $this->config[website][url];

您将配置参数作为数组访问,这对您有用,所以使用它吗?

使用时

 $this->config->website->url;

您像访问对象一样访问配置,这是失败的,所以不要使用它?

如果它以一种方式工作,那么问题是什么,您是否需要对配置参数使用对象表示法?