我有一个助手叫做Zend_View_Helper_FormVars
,它被我的一个模块使用。
我还有一个常用的助手在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;
}
}
以下是 GeneralFunctions.php
中的代码:
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;
}
}
另外,我忘了提到我已经像这样在引导程序中自动加载了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();
//-------------------->
我收到的错误信息是:
致命错误:在第2行中未找到“Common_Helper_General”类,路径为/Applications/MAMP/htdocs/mysite/application/modules/dashboard/views/helpers/DashboardHelper.php。