框架主要是为了提高开发效率和支持多人团队开发而发明的。传统的平面式开发总是让每个软件项目从零开始,程序员不得不重复“制造轮子”的工作;而界面 (html+css+javascript)与程序逻辑的混杂使程序员与界面制作的角色很难分离开来,这有可能使得应用程序在其生命周期中变得无法维护。
ZF的做法是,为了提高应用程序的可维护性,它将程序的代码分成如下三个不同的部分(通常也是独立的文件):
模型(M):应用程序的模型部分。关心的是显示的数据的细节。模型通常关注的是业务逻辑,以及如何从数据库中存取数据。在具体的代码中表现为一个一个不同的类,可以看做是一个用户自定义的类库。
视图(V):视图关心的是用户显示的内容,它通常是HTML。
控制器(C):控制器将模型和视图结合起来,保证将正确的数据显示到页面上。
也就是说,Zend Framework使用Model-View-Controller(MVC)架构。它将程序中不同的部分独立开来,使得应用程序的开发和维护变得更加容易。
1,ZF框架的设计思想和策略
ZF采用了前端控制器(Front Controller)设计模式,它把所有用户的请求发送到一个中心控制点,具体做法就是所有的请求都需要通过index.php进入。然后通过 index.php中的脚本把用户请求分发到对应的控制器中,控制器负责调用模型中的逻辑和用户界面的呈现。
2,Apache对ZF的支持
为了实现ZF的设计思想,需要Web服务器的支持。Apache服务器是通过其mod_rewrite功能来实现的。
2.1配置mod_rewrite扩展需要去掉Apache的配置文件httpd.conf中以下语句前的注释符号#,使配置生效,即装载mod_rewrite.so模块。
LoadModule rewrite_module modules/mod_rewrite.so
还必须保证Apache已配置成支持.htaccess文件的模式。通常这可以通过在httpd.conf中将
<Directory "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"> Options Indexes FollowSymLinks #AllowOverride None AllowOverride All Order allow,deny Allow from all </Directory>
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php …htdocs
app_phpchina1.com
controllers
models
views
library
Zend
phpchina1.com
phpchina1.com文件夹下存放index.php和.htaccess文件;
Controllers存放控制器文件;
models存放控制器文件;
views存放视图文件;<?php error_reporting(E_ALL|E_STRICT); //设定时区 date_default_timezone_set('Asia/Shanghai'); //指明引用文件的路径 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATOR . '../App_phpchina.com/models/'. PATH_SEPARATOR . get_include_path()); include "Zend/Loader.php"; Zend_Loader::registerAutoload(); $fc = Zend_Controller_Front::getInstance(); $fc->setControllerDirectory(array( "default"=>'../app_phpchina1.com/controllers', )); $fc->throwExceptions(true); $fc->setParam('noViewRenderer', true); $fc->setParam('noErrorHandler', false); //开始运行程序 $fc->dispatch(); ?>
<?php class IndexController extends Zend_Controller_Action { function indexAction() { echo "Hello PHPChina1.com!"; } function otherAction() { echo "this is other Action."; } } ?>
评论
wwwww
星期五, 12/25/2009 - 01:59 — zixinYou're louis vuitton handbags surely aware that your Gucci cellphone bleeds radiation into your Gucci handbags face the Gucci Bags whole time you're on the Gucci Bag phone with your mom Gucci Purses, best friend or lover, right rolex? Yes, it's a rolex watches fact we try not to think about most of the time, but now there's a tool out there on the internets for the more reality-facing folks among us.