第一次接触框架的人,都会有被框架的约束条件搞得晕忽忽的感觉。经常是写了一推代码,却只得到错误信息。因此本文www.phpchengdu.com的主要目的在于帮助准备学习ZF的朋友认识与理解zf的标准组织结构,少走弯路。
一:所有的功能都放在application目录下,在这人目录下面在按不同的模块建立文件夹
比如application/student application/teacher 并且在配置文件中注册这两个模块。注册的方法见上一篇我所介绍的方法。
二:在student目录下建立至少二个标准目录 controllers views
application/student/controllers 用于存放控制器文件,也就是php程序
application/student/views 用于存放页面文件等
三:在application/student/controllers中建立控制器文件,控制器文件的名称要与类的名称一致
如:studentController.php
四:在studentController.php建立类的定义
其类名必须由模块名、控制器名组成
如class student_studentController extends Zend_Controller_Action
五:在类时添加方法
如编辑,新增,删除等。则对应的方法的名称为
public function editAction()
public function addAction()等
六:在application/student/views文件夹中创建scripts目录
七:在application/student/views/scripts根据对应的控制器创建每个控制的模板目录,如上例中控制器为student,则建立
application/student/views/scripts/student目录。
八:在application/student/views/scripts/student目录根据控制器中每个action创建各自对应的表现层。根据上例中的动作,则应该创建
application/student/views/scripts/student/edit.phtml
application/student/views/scripts/student/add.phtml
等。
这样一个完整的且标准的程序结构就完成了。刚开始觉得很麻烦,一旦熟悉后,你会发现这种方法是很幽雅的。
罗维

