/helper_demo1/application/controllers/IndexController.php
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function testAction(){
//$this->view->addHelperPath('/home/coder/www/helper_demo1/library/Test/Helper', 'Test_Helper');
//或者因为在includepath已经设置library,所以可以直接:
$this->view->addHelperPath('Test/Helper', 'Test_Helper');
}
/helper_demo1/library/Test/Helper/MyHelper.php即绝对路径是/home/coder/www/helper_demo1/library/Test/Helper/MyHelper.php
文件内容:
<?php
require_once 'Zend/View/Interface.php';
/**
* MyHelper helper
*
* @uses viewHelper Test_Helper
*/
class Test_Helper_MyHelper {
/**
*
* @var Zend_View_Interface
*/
public $view;
/**
*/
public function myHelper() {
return "this my helper return !".rand(1, 10);
}
/**
* Sets the view field
*
* @param $view Zend_View_Interface
*/
public function setView(Zend_View_Interface $view) {
$this->view = $view;
}
}
对应action的phtml调用方法
<?php
echo $this->myHelper();
?>