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

发布于 2024-11-06 13:33:05 字数 1456 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执妄 2024-11-13 13:33:06

尝试一下:)

Bootstrap:

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

以及您想要使用它的位置:

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

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

Give this a whirl :)

Bootstrap :

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

And where you want to use it :

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

You were storing an array in options not an an object (Zend_Config)

迷鸟归林 2024-11-13 13:33:06

当使用

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

Your accessing the config parmeters as an array 时,这对您有用,所以使用它吗?

当使用

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

Your accessing the config 就像它是一个对象时,这是失败的,所以不要使用它?

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

When using

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

Your accessing the config parmeters as an array, this is working for you, so use it?

When using

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

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文