Php zend 1 view helper函数在另一个view helper类中使用
我有两个助手类 链接为: C:\xampp\htdocs\ecom\application\views\helpers\comman.php C:\xampp\htdocs\ecom\application\views\helpers\RefineUrl.phpPhp zend 1 view helper函数在另一个view helper类中使用,php,zend-framework,helper,Php,Zend Framework,Helper,我有两个助手类 链接为: C:\xampp\htdocs\ecom\application\views\helpers\comman.php C:\xampp\htdocs\ecom\application\views\helpers\RefineUrl.php class Zend_View_Helper_Refinestr { public function Refinestr($str, $options = array()){ .............. .
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
} }
如何在另一个helper类函数中使用一个helper类函数?您可以在您的案例中使用以下技巧 从
视图
文件调用getPageContent()
帮助程序时,将帮助程序中的视图对象
作为参数
(如$pageId
)传递,并使用该视图对象
调用帮助程序定义中的另一个帮助程序
查看
文件:
<?php echo $this->getPageContent($pageId, $this); ?>
另一个助手将保持原样
此问题的另一个解决方案是,在引导时在Zend Registry
中设置view object,并使用helper文件中的注册表变量
调用另一个helper
在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
$this->helper1()->view->helper2();
如果helper1接受一些参数,我将其修改为不接受任何参数并返回。试试看,可能有用
$this->helper1()->view->helper2();