我有一个叫做Zend_View_Helper_FormVars的助手,我的一个模块使用过它.
我在application / common / helpers / GeneralFunctions.PHP中也有一个共同的帮助器
我在application / common / helpers / GeneralFunctions.PHP中也有一个共同的帮助器
我正在尝试从GeneralFunctions.PHP中的Zend_View_Helper_FormVars调用一个函数.
这是Zend_View_Helper_FormVars的简短版本:
class Zend_View_Helper_FormVars { public $reqFieldVisual='<span class="req">*</span>'; public $roles=array('admin'=>'admin','user'=>'user'); public $paymentMethods=array('1'=>'Check','2'=>'Credit Card','3'=>'Cash','4'=>'Other'); public function formVars(){ $this->baseUrl=Zend_Controller_Front::getInstance()->getBaseUrl(); return $this; } public function mkCategoryCodeSelectGroup($codeTypeArr=array(),$codesArr=array()) { $html=''; $html.=Zend_View_Helper_GeneralFunctions::generalFunctions()->progressMeter(); return $html; } }
class Zend_View_Helper_GeneralFunctions { public function generalFunctions(){ $this->baseUrl=Zend_Controller_Front::getInstance()->getBaseUrl(); return $this; } public function progressMeter() { $html=''; $html.='<span id="progressWrapper">'; $html.='<span id="progressMeter"></span>'; $html.='</span>'; $html.=''; return $html; } }
另外,忘了提一下我在这样的Bootstrap中自动加载了GeneralFunctions帮助器,它已经可用于我的所有模块了:
$view->addHelperPath(APPLICATION_PATH .'/common/helpers','View_Helper');
这是我尝试过的,但是收到错误:
// application/Bootstrap.PHP -----------> function _initViewHelpers() { // add a helper for use for all modules $view->addHelperPath(APPLICATION_PATH .'/Common/Helper','Common_Helper'); } //--------------------> // application/common/helpers/General.PHP -----------> class Zend_View_Helper_General extends Zend_View_Helper_Abstract { public function general(){ return $this; } public function test(){ return 'test 123'; } } //--------------------> // application/modules/dashboard/views/helpers/DashboardHelper.PHP -----------> class Zend_View_Helper_DashboardHelper extends Common_Helper_General { public function dashboardHelper(){ return $this; } public function dashboardTest(){ return 'from dashboard'; } } //--------------------> // application/modules/dashboard/views/scripts/index/index.phtml -----------> echo $this->dashboardHelper()->test(); //-------------------->
我收到错误消息:
Fatal error: Class ‘Common_Helper_General’ not found in /Applications/MAMP/htdocs/mysite/application/modules/dashboard/views/helpers/DashboardHelper.PHP on line 2
调用另一个View Helper实际上非常简单.
原文链接:https://www.f2er.com/php/137968.html确保您的视图助手扩展了Zend_View_Helper_Abstract,以便它可以访问$view.那么你可以像在视图中那样简单地给助手打电话,即
$this->view->generalFunctions()->progressMeter();
根据您上面的示例:
<?PHP class Zend_View_Helper_FormVars extends Zend_View_Helper_Abstract { /* ... */ public function mkCategoryCodeSelectGroup($codeTypeArr=array(),$codesArr=array()) { $html=''; $html. $this->view->generalFunctions()->progressMeter(); return $html; } }