国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > php框架 > ZendFramework > Zend Framework教程-Zend_Helpers-视图助手-创建自己的视图助手-demos2

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

来源:程序员人生   发布时间:2013-11-23 05:36:39 阅读次数:4419次

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




生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生