程序员人生 网站导航

Zend Framework教程-Zend_Helpers-视图助手-创建自己的视图助手-demos2

栏目:ZendFramework时间:2013-11-23 05:36:39

/helper_demo1/application/controllers/IndexController.php 

<?phpclass 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

文件内容:

<?phprequire_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();?>




------分隔线----------------------------
------分隔线----------------------------

最新技术推荐