Coding Samples, Tutorials, Code Snippets, Articles, How-To`s - From Beginners to Expert. Stay tuned.
Share your knowledge. Regardless what experience you have made with the Zend Framework - Let all benefit.

Search Manual:

Please Sign in or Register

Available Languages

 


Manual for Zend Framework 1.0.3

7.2. Zend_Controller 基础

Zend_Controller系统被设计为轻量、模块化、和可扩展的系统。虽然它提供了足够多的功能结构让你的系统建立在Zend_Controller之上并共享通用的约定和相似的代码设计,但它是一个最低要求的设计,给用户最大的灵活性和自由度。

The following diagram depicts the workflow, and the narrative following describes in detail the interactions: (注:没有理解,请翻译后去掉这个注释 Jason Qi)

Zend_Controller工作流用若干组件来实现。虽然不需要完全理解所有组件的基础知识来使用它,但是拥有工作流程的知识很有帮助。

  • Zend_Controller_Front 控制了Zend_Controller系统的整个工作流。它是前端控制器(FrontController)模型的解释。Zend_Controller_Front处理所有由服务器接收的请求并负责把请求派发给动作控制器(ActionControllers)(Zend_Controller_Action)。

  • Zend_Controller_Request_Abstract (often referred to as the Request Object)描述请求环境和提供设置和读取控制器和动作名字以及任何请求参数的方法。另外它跟踪它所包含的动作是否被Zend_Controller_Dispatcher派遣。抽象请求对象的扩展可被用来封装整个请求环境,为了设置控制器和动作的名字,它允许路由器从请求环境中读出信息。

    缺省地,Zend_Controller_Request_Http被用来访问整个HTTP请求环境。

  • Zend_Controller_Router_Interface用来定义路由器。路由是个过程,在这个过程中它通过检查请求环境来决定哪个个控制器和哪个控制器中的动作应该接受请求。控制器、动作和可选的参数就通过Zend_Controller_Dispatcher_Standard处理来设置在请求对象中。路由只发生一次:在最初收到请求并在第一个控制器被派遣之前。

    缺省路由器,Zend_Controller_Router_Rewrite,从Zend_Controller_Request_Http取出URI的终点作为参数并基于在url中的路径信息分解成控制器、动作和参数。作为一个例子,URL http://localhost/foo/bar/key/value将被解析为foo控制器、bar 动作和带有一个值value的参数key

    Zend_Controller_Router_Rewrite也可以用来匹配任意的路径;参见路由器文档 有更多的信息。

  • Zend_Controller_Dispatcher_Interface被用来定义派遣器。派遣是个过程,在这个过程中它从请求对象中取出控制器和动作并映射它们到控制器文件/类和在控制器中的动作方法。如果控制器和动作不存在,它派遣缺省的控制器和动作。

    实际的派遣过程包括初始化控制器类和在这个类中调用动作方法。不像路由,只发生一次,派遣是循环发生的。如果请求对象的派遣状态在任何点上重置,循环将被重复,调用不论哪个当前在请求对象中的动作。第一次循环随请求对象的派遣状态设置(布尔 true)完成,它将完成处理。

    缺省的派遣器是Zend_Controller_Dispatcher_Standard。它定义控制器为以Controller结尾的CamelCasedClasses,并且动作为以Action结尾的camelCasedMethods:FooController::barAction()。在这个例子中,控制器是foo,动作是the action as bar

  • Zend_Controller_Action是基本的动作控制器组件。每个控制器是一个从Zend_Controller_Action class扩展的单个的类并且应该包含一个或更多的动作方法。

  • Zend_Controller_Response_Abstract定义了一个基本的响应类,用来从动作控制器收集和返回响应。头和body的内容它都收集。

    缺省的响应类是Zend_Controller_Response_Http,它适合用于HTTP环境。

Zend_Controller的工作流相当简单。请求被Zend_Controller_Front接收,然后它调用Zend_Controller_Router_Rewrite来决定哪个控制器(和控制器中的动作)被派遣。为了在请求中设置控制器和动作名字Zend_Controller_Router_Rewrite分解URI。Zend_Controller_Front接着进入一个派遣循环。它调用Zend_Controller_Dispatcher_Standard,传递给它请求,派遣在请求(或使用缺省的)中指定的控制器和动作。在控制器完成之后,控制返回到Zend_Controller_Front。如果控制器通过重置请求派遣状态指示其它的控制器应该被派遣,循环将继续并且其它派遣被执行。否则,处理结束。

Welcome!

Welcome to ZFResource - The Resource for the Zend Framework.
As you see, the website is in still in progress. Many features ( like Code Directory, Code Samples, User written Tutorials, Examples and News,...) will be online in near future.
At the moment, you can search and browse the manual in your language of choice. Don't forget to come back later to benefit from the new features.


Help Wanted:

We are still searching for people want to help building this site. If you want to see this website in your language or you have any suggestions for this site please send us an email