`

【转】Using partial helpers in Zend Framework

阅读更多

      在了解Zend Framework的Partial View Helper的过程中,Google了一篇相关的使用入门介绍,现转贴于下。文中提供的

源码下载,也上传了一份。


      Using partial helpers in Zend Framework


ZendFrameworkQuickstart application is demo guestbook with Zend library files included,
basic folder structure and some sample data for fetching and entering new.
It is already configured for usage and always updated with the latest release of Zend Framework.

The quickest way to setup Zend FrameworkQuickstart app for you is next 2 steps:
1.you need to download ZendFrameworkQuickstart application files
2.and setup virtual host pointing to public folder (e.g. /var/www/zend.quickstart/public/)

I used ZendFrameworkQuickstart application for you so you can easier test the code I provided.
You just need to download and setup latest ZendFrameworkQuickstart and replace default files with files I posted.
Here is the post:

In layout file (our case “layout.phtml” in application/layouts/scripts/)
we just need to call helper $this->partial and correct path to partial file

<div id="categories">
    < ?php echo $this->partial('partials/categories.phtml',
				            array('categories' => $this->data)); ?>
</div>
 

with correct “keys” and “values” (our case ‘categories’ and $this->data).
Key (‘categories’) will stand for entity which is iterrated in our partial file in foreach loop
(our case “categories.phtml” in application/layouts/scripts/partials)

<ul>
< ?php foreach($this->categories as $item) : ?>
	<li class="item">
	  <a href="<?php echo $this->url(
	  					array(
							"cat"=>$item['key'],
                                                        "action"=>"index",
	  						"controller"=>"index",
	  						"module"=>"default"
	  										))?>">
		< ?php echo $item['value']; ?></a>
    	</li>
< ?php endforeach; ?>
</ul>
 

and value ($this->data) must be defined in our controller class file as a view helper ($this->view->data),
I defined it in init() method so it will be set for all actions in IndexController.

public function init()
	{
		$this->view->data =
				array(
					array('key' => 'key_1', 'value' => 'category_1'),
					array('key' => 'key_2', 'value' => 'category_2'),
					array('key' => 'key_3', 'value' => 'category_3'),
					array('key' => 'key_4', 'value' => 'category_4'),
				);
	}
 

I added demoAction so you can try to set different data set or you can try to play with the code and create some data set from query result.
Enjoy.

分享到:
评论

相关推荐

    ZendFramework中文文档

    1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) 2.1.4. 注册角色(Role) 2.1.5. 定义访问...

    诗意的边缘:PHP顶级框架Zend Framework开发实战-代码

    ** Zend Framework 框架详解** Zend Framework 是一个开源、基于组件的 PHP 开发框架,专为构建可扩展且高性能的 Web 应用程序而设计。它的设计模式遵循了 Model-View-Controller(MVC)架构,使得开发者可以更加...

    ZendFramework-1.7.2帮助文档

    **Zend Framework 1.7.2 帮助文档** Zend Framework 是一个开源、全面的 PHP 框架,用于构建可扩展且高效的 Web 应用程序。版本 1.7.2 是该框架的一个重要里程碑,包含了丰富的特性和改进。这个帮助文档以 HTML ...

    Zend Framework教程之视图组件Zend_View用法详解

    在Zend Framework中,Zend_View是模型-视图-控制器(MVC)架构中视图层的重要组成部分,负责处理和呈现应用程序的输出。本教程将深入探讨Zend_View的使用方法、工作原理及其与其他组件的交互。 首先,让我们了解...

    zendframework 分页实现

    本篇文章将深入探讨如何在Zend Framework中利用`Zend_Paginator`组件实现高效的数据库查询分页。 `Zend_Paginator`是Zend Framework的一个核心组件,它的主要功能是帮助开发者在大量数据中创建用户友好的分页界面。...

    Zend Framework基本页面布局分析

    在Zend Framework中,页面布局是指web页面的整体结构设计,它涉及页面的头部(header)、主体内容区(content)、边栏(leftcolumn)、页脚(footer)等多个部分,通过布局脚本(如layout.phtml)和其它视图脚本(如...

    Partial Differential Equations in Physics

    《偏微分方程在物理学中的应用》是索末菲的杰作,主要阐述了偏微分方程在物理学,尤其是热学、电磁学领域的应用。出版于上世纪中期,这本书成为物理学研究不可或缺的参考书籍。 在这本书中,索末菲首先阐述了偏微分...

    computational partial differential equations using matlab.pdf

    本书《Computational Partial Differential Equations Using MATLAB®》针对工科研究生和博士生提供了一种使用MATLAB软件来求解偏微分方程的数值方法。同时,本书也适合工程人员作为参考手册,以学习和应用偏微分...

    Taking Partial Derivatives in Calculus.zip

    这个"Taking Partial Derivatives in Calculus.zip"压缩包显然聚焦于如何在MATLAB环境中计算和理解偏导数。MATLAB是一款强大的数学软件,广泛应用于科学计算、工程分析以及数据分析等领域。 首先,让我们深入了解...

    Image Processing Based on Partial Differential Equations 基于偏微分方程的图像处理part 4 0f 4

    This book publishes a collection of original scientific research articles that address the state-of-art in using partial differential equations for image and signal processing. The topics covered in ...

    First Course in Partial Differential Equations

    First Course in Partial Differential Equations - H. Weinberger (1965) WW.djv

    C# partial关键字说明

    使用`partial`关键字能够极大地提升代码的可管理性,特别是在与代码生成工具(如Entity Framework的DbContext)配合时,可以将自动生成的代码与手动编写的业务逻辑代码分开,降低代码维护难度。例如,对于一个`...

    Partial-Discharges-in-Electrical-Insulation.pdf

    英文局部放电资料、高电压、绝缘。介绍了局部放电的原理、种类和其对电气设备的危害。介绍了局部放电特征值提取的方法以及各种模式识别

    Image Processing Based on Partial Differential Equations 基于偏微分方程的图像处理 part 2 0f 4

    This book publishes a collection of original scientific research articles that address the state-of-art in using partial differential equations for image and signal processing. The topics covered in ...

    Active contour extraction method using partial shape constraint contour model

    Active contour extraction method using partial shape constraint contour model Active Contour Extraction Method Using Partial Shape Constraint Contour Model Masahide Nishiura, Mayumi Yuasa, and ...

    Numerical Partial Differential Equations in Finance Explained An epub

    Numerical Partial Differential Equations in Finance Explained An Introduction to Computational Finance 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网...

    Lambda FIX II/Xho I Partial Fill-In Vector Kit.pdf

    文档标题《Lambda FIX II/Xho I Partial Fill-In Vector Kit.pdf》和描述指出了该文档与一个特定的分子生物学实验试剂盒相关,即Lambda FIX II/Xho I 部分填充法载体试剂盒。试剂盒包含了用以进行DNA克隆或基因库...

    CFD经典著作:numerical partial differential equation - finite difference method

    Prerequisites suggested for using this book might include one semester of partial differential equations and some programming capability. This book will be a good reference text for students." -- ...

    ZYNQ7000 Partial Reconfiguration.docx

    ZYNQ7000 Partial Reconfiguration ZYNQ7000 的 Partial Reconfiguration 是一种动态可重配技术,它允许在不中断系统运行的情况下,重新配置 FPGA 中的某些模块。这种技术可以提高系统的灵活性和可维护性。 在 ...

Global site tag (gtag.js) - Google Analytics