问题描述
使用...$this->getInvokeArg('bootstrap')->getOptions();
.. 从 application.ini 检索我的配置设置(使用 Zend Framework 1.11).这在从 Zend Helper 文件调用时失败,但在控制器中调用时有效
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
为什么?
推荐答案
getInvokeArg() 方法存在于控制器(扩展 Zend_Controller_Action 的类),但不适用于动作助手(扩展 Zend_Controller_Action_Helper_Abstract 的类 - 我想这就是Zend 助手文件"的意思).您可以在 Zend Framework API 中确认这一点,这是在开发时非常有用的参考Zend 框架.
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.
要在动作助手中调用 getInvokeArg(),您必须首先获取当前动作控制器,您可以通过调用 getActionController() 方法在动作助手中执行此操作.最后,在动作助手中,以下代码将执行您想要的操作:
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();
$this 关键字指的是当前类;因此,在动作助手中,$this 指的是动作助手,而不是控制器.
The $this keyword refers to the current class; as such, within an action helper, $this refers to the action helper, and not the controller.
这篇关于$this->getInvokeArg('bootstrap')->getOptions();从 Zend Helper 文件调用时失败 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!