我有两个辅助类
链接是:
C:\ XAMPP \ htdocs中\ ECOM \应用\视图\助手\ comman.php
C:\ XAMPP \ htdocs中\ ECOM \应用\视图\助手\ RefineUrl.php
class Zend_View_Helper_Refinestr
{
public function Refinestr($str, $options = array()){
..............
.............
return $str;
}
}
第二是
class Zend_View_Helper_Comman
{
public function Comman(){
return $this;
}
public function getPageContent($pageId){
// return $pageId;
$mapper = new Application_Model_StaticpageMapper();
$selectedFields=array('desc');
$tblName=array($mapper->getDbTable()->_name);
$whr= "`id`=$pageId";
$content=$mapper->fetchSelectedFields($tblName,$selectedFields,$whr);
$des=$content[0]['desc'];
// here i want to use function Refinestr() of another helper class how i use this
$des=$this->Refinestr($des);
// not working , searching this function inside comman class
} }
如何在另一个辅助类函数中使用一个辅助类函数?
答案 0 :(得分:1)
您可以根据自己的情况使用以下技巧。
从您的getPageContent()
文件中调用view
帮助程序时,将view object
作为param
传递给$pageId
view object
并使用View
在helper定义中调用另一个帮助器。
<?php echo $this->getPageContent($pageId, $this); ?>
档案:
class Zend_View_Helper_GetPageContent {
public function getPageContent($pageId, $viewObj) {
// return $pageId;
$mapper = new Application_Model_StaticpageMapper ();
$selectedFields = array ('desc'
);
$tblName = array ($mapper->getDbTable ()->_name
);
$whr = "`id`=$pageId";
$content = $mapper->fetchSelectedFields ( $tblName, $selectedFields, $whr );
$des = $content [0] ['desc'];
// here i want to use function Refinestr() of another helper class how i
// use this
$des = $viewObj->Refinestr($des); //use view object to call another helper
}
}
帮助文件:
Zend Registry
另一个助手将保持不变。
此问题的另一个解决方案可能是,在引导时在registry variable
中设置视图对象,并使用辅助文件中的Bootstrap
来调用另一个帮助程序。
在protected function _initConfig() {
$this->bootstrap('view');
$this->_view = $this->getResource('view');
Zend_Registry::set('viewObj', $this->_view);
}
文件中:
Helper
class Zend_View_Helper_GetPageContent {
public function getPageContent($pageId) {
// return $pageId;
$mapper = new Application_Model_StaticpageMapper ();
$selectedFields = array ('desc');
$tblName = array ($mapper->getDbTable ()->_name);
$whr = "`id`=$pageId";
$content = $mapper->fetchSelectedFields ( $tblName, $selectedFields, $whr );
$des = $content [0] ['desc'];
// here i want to use function Refinestr() of another helper class how i
// use this
$viewObj = Zend_Registry::get('viewObj');
$des = $viewObj->Refinestr($des); //use view object to call another helper
}
}
文件:
{{1}}
答案 1 :(得分:1)
我通常会做以下事情:
内部helper1
$this->helper1()->view->helper2();
如果helper1正在接受一些参数,我将其修改为不带参数并返回。尝试一下,可能会有效。