开发者

Zend config.ini parameters referred from a script

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_Reg开发者_如何学Cistry::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


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)


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜