$this->getInvokeArg('bootstrap')->getOptions(); fails when called from Zend Helper file - why?

▼魔方 西西 提交于 2019-12-08 10:50:52

问题


using ... $this->getInvokeArg('bootstrap')->getOptions(); .. to retrieve my config settings from application.ini (using Zend Framework 1.11). this is failing when called from a Zend Helper file but works when called in a controller

why?


回答1:


The getInvokeArg() method exists for controllers (classes extending Zend_Controller_Action), but is not available for action helpers (classes extending Zend_Controller_Action_Helper_Abstract - I suppose that is what you mean with "Zend Helper file"). You can confirm this in the Zend Framework API, which is a very useful reference when developing with the Zend Framework.

To call getInvokeArg() within an action helper, you must first get the current action controller, which you can do within action helpers by calling the getActionController() method. Concluding, within an action helper, the following code will do what you want:

$this->getActionController()->getInvokeArg('bootstrap')->getOptions();

The $this keyword refers to the current class; as such, within an action helper, $this refers to the action helper, and not the controller.



来源:https://stackoverflow.com/questions/6219805/this-getinvokeargbootstrap-getoptions-fails-when-called-from-zend-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!