当前位置: 首页 > 图文教程 > 网络编程 > PHP > Zend framework处理一个http请求的流程分析

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP 中的 Zend framework处理一个http请求的流程分析


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-02-27   浏览: 85 ::
收藏到网摘: n/a

Zend framework处理一个http请求的流程分析,有助于大家提高知识面。

zend framework 处理请求流程图

1, 首先是bootstrap过程,初始化程序里用到的资源

2, 创建一个Zend_Controller_Front实体,实现front controller模式,这个实体类会负责将http请求派遣到恰当的controller的action里。

3, Front controller会创建俩个对象来封装http请求和http回复,分别是Zend_Controller_Request_Http和Zend_Controller_Response_Http

4, Front controller会创建俩个对象来实现url寻路和派遣,分别是routing和dispatcher, 分别负责找到指定url应该执行的控制器和动作,和载入对应的程序文件并执行对应的方法。

5, 通过controller的plugin机制,Zend_Controller_Action_ViewRenderer会为controller的实体类创建一个view属性,这个view是一个Zend_View的实体对象。它还负责在controller action请求处理完成后,将相应的template文件render呈现到http response对象里。最后response对象的内容会由Front Controller输出到浏览器。

6, 在第五步中,虽然template文件是由ViewRender助手对象来定位的,但是是由Zend_VIew的一个成员函数执行的(include进这个template文件),所以在Controller里属性里view对象的所有属性和成员函数在template文件里都可以被使用。

这样一个http请求的生命周期就结束了,浏览器获得了内容。在controller的action给view指定要呈现的变量时,它一般会通过Zend_Db_Table与数据库交互,获得数据。

与数据库交互处理数据称为business logic, template文件里也会包涵简单的循环等逻辑,这个称为display logic。

在MVC实现中,Model负责处理business logic, View负责处理display logic,而Controller则负责协调这俩部分,从而Controller的代码应该尽量简洁,它只是作为一个agent存在的。