从脚本引用的 Zend config.ini 参数
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');
}
}
我的IndexController:
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!
}
}
谢谢卢卡
我的
Zend framework talk.I knew that:
"When referring to configuration parameters within a script,
you'll prefix it with $this->config and converting the periods
to right-facing arrows"
ISSUE: However when I try to echo "$this->config->website->url;" I dont have output.
If I try with "$this->config[website][url]" I receive the correct output.
Where Am I wrong?
I have:
my bootstrap class:
[..]
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 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');
}
}
my IndexController:
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!
}
}
thanks
Luca
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下:)
Bootstrap:
以及您想要使用它的位置:
您将数组存储在选项中而不是对象中(Zend_Config)
Give this a whirl :)
Bootstrap :
And where you want to use it :
You were storing an array in options not an an object (Zend_Config)
当使用
Your accessing the config parmeters as an array 时,这对您有用,所以使用它吗?
当使用
Your accessing the config 就像它是一个对象时,这是失败的,所以不要使用它?
如果它以一种方式工作那么问题是什么,您是否需要对配置参数使用对象表示法?
When using
Your accessing the config parmeters as an array, this is working for you, so use it?
When using
Your accessing the config as if it is an object, this is failing, so don't use it?
If it works one way then what is the problem, do you need to use the object notation for the config parameters?