我只是想到了一个解决方法。您只需要手动调用帮助程序,而不是让 ZF 通过call_user_func_array
.
参考.php
class Zend_View_Helper_Ref extends Zend_View_Helper_Abstract
{
public function removeFromRef(&$ref)
{
// change your var value here
unset($ref['key']);
}
/**
* ZF calls this for us, but we'll call what we want, so you can skip this.
*/
// public function ref()
// {}
}
如您所见,您可以跳过必须将 main 方法命名为文件名的约定,但我仍然推荐它。现在,您可以在视图/控制器中传递引用:
// in view:
$this->getHelper('Ref')->removeFromRef($someVar2Change);
// in controller
$this->view->getHelper('Ref')->removeFromRef($someVar2Change);
基本上,这就是$this->ref()
:获取助手,然后调用call_user_func_array
.
有些人可能在使用$this->getHelper('Ref')->ref()
而不是$this->ref()
虽然有问题,但它确实有效。