Php 从脚本引用的Zend config.ini参数
Zend framework talk。我知道:Php 从脚本引用的Zend config.ini参数,php,zend-framework,config,Php,Zend Framework,Config,Zend framework talk。我知道: "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
"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');
}
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!
}
}
mymy\u Action\u Helper\u初始值设定项:
[..]
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');
}
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 =$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');
}
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!
}
}
谢谢
Luca在使用时
$this->config[website][url];
$this->config->website->url;
您将配置参数作为数组访问,这对您有效,所以使用它吗
使用时
$this->config[website][url];
$this->config->website->url;
如果您像访问对象一样访问配置,这是失败的,所以不要使用它
如果它以一种方式工作,那么问题是什么,您是否需要对配置参数使用对象表示法
引导:
protected function _initConfig(){
$config = new Zend_Config($this->getOptions(), true);
Zend_Registry::set('config', $config);
return $config;
}
以及您想在哪里使用它:
$config = Zend_Registry::get('config');
您将数组存储在选项而非对象(Zend_Config)中。我正在引用一本书。如果找不到作者所写的内容,请提醒我。我没有做好准备,因此我想了解为什么会发生此问题?你知道吗?=)$config=new Zend_config($this->getOptions(),true);重要的一点。