Your SlideShare is downloading. ×
0
Zend Framework 陈浩 2008.10.22
<ul><li>陈浩  haohappy </li></ul><ul><li>Chinese Translator of: </li></ul><ul><li>Programming PHP  2 nd  edition  《 PHP 程序设计...
PHP Objects, Patterns and Frameworks <ul><li>PHP4 退出历史舞台, PHP5 成为主流 </li></ul><ul><li>PHP5 对于面向对象的支持大大加强 </li></ul><ul><ul...
Contents of this presentation <ul><li>Brief Introduction of ZF </li></ul><ul><li>MVC  </li></ul><ul><li>Database </li></ul...
场景:川菜馆 顾客看菜谱  顾客:来一盘鱼香肉丝 服务员:好咯 服务员告诉大厨: 2 号桌要一盘鱼香肉丝 大厨辛苦劳动。。炒炒炒 搞定。告诉服务员:炒好了。 服务员把菜端给顾客 MVC 的含义 MODEL VIEW CONTROLLER
Zend Framework <ul><li>开放源代码的 PHP5 开发框架  </li></ul><ul><li>易于学习和使用 </li></ul><ul><li>功能强大,促进快速开发 </li></ul><ul><li>有活跃的开发者...
 
MVC in ZF Zend_Db_Table Zend_View Zend_Controller
MVC in ZF 单一入口: index.php 项目文件目录分布
Bootstrap ( 入口文件 ) <ul><li><?php  //  控制器实例化  $controller =  Zend_Controller_Front :: getInstance ();  $controller -> setC...
Zend_Controller
Zend_Controller 用户访问: http://www.phpeye.com/article/view/id/1 Apache Server:  url_rewrite 转向所有请求到入口文件  index.php  index.ph...
Zend_Controller <ul><li>Zend_Controller_Front  </li></ul><ul><li>设置 controller 目录,生成 request 对象,并 dispatch() </li></ul><ul...
Zend_Controller <ul><li>class  ArticleController  extends  Zend_Controller_Action  {      public function  indexAction () ...
Model  -  DB <ul><li>1.  数据库软件的抽象  基于 PDO (PHP Data Objects) </li></ul><ul><ul><ul><li>MySQL, OCI, PostgreSQL, ODBC, DB2, ...
Table Data Gateway <ul><li>An object that acts as a Gateway to a database table. One instance handles all the rows in the ...
Active Record <ul><li>An object that wraps a row in a database table or view, encapsulates the database access, and adds d...
CRUD Zend_Db_Table $rows_affected = $this->insert($data); $rows_affected = $this->update($data, $where); $rows_affected = ...
Zend_View <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title ><?php echo $title ?></title> </li></ul><ul><li...
Zend_View <ul><li>PHP is template language itself. You don’t need another one. Just separate your logic from your presenta...
PHP & Web 2.0
Zend Framework & Web 2.0 <ul><li>Json, Soap, Rest, XmlRpc, Amf new , Dojo,   Gdata </li></ul><ul><li>Zend_Services_*  针对某个...
Zend Framework & Web 2.0 Json Built-in functions of PHP 5.2 +  json_decode()  json_encode() <ul><li>Zend_Json </li></ul><u...
Zend Framework & Web 2.0 Json Back
Zend Framework & Web 2.0 Json // fromXml function simply takes a String containing XML contents as input. $jsonContents = ...
Zend Framework & Web 2.0 Json Back
Zend Framework & Web 2.0 Gdata http://code.google.com/apis/gdata/ <ul><li>Google Calendar   </li></ul><ul><li>Google Sprea...
Zend Framework & Web 2.0 <ul><li>Zend_Services_*  针对某个特定网站的 API 访问客户端 </li></ul><ul><ul><li>Zend_Service_Akismet  </li></u...
Zend Framework & Web 2.0 REST Zend_Rest_Client Zend_Rest_Server
Zend Framework & Web 2.0 REST Zend_Rest_Client $serverUrl =  'http://framework.zend.com/rest'; $client = new Zend_Rest_Cli...
Zend Framework & Web 2.0 REST Zend_Rest_Client /** *  在 Technorati 上查找某个博客的作者 */ $technoratiUrl =  'http://api.technorati....
Zend Framework & Web 2.0 REST Zend_Rest_Server $server = new Zend_Rest_Server(); $server->setClass('My_Service_Class'); $s...
Zend_Amf 支持  Adobe 的  Action Message Format  (AMF) 允许浏览器端的 Flash Player   与 PHP 进行通信 .  另外,可以将 Actions Script 中的数据(如对象)方便地...
Useful libs <ul><li>Auth, Acl, Form, Layout, Cache, Config, Paginator, Mail, Validate, Http </li></ul>
ZF & RoR <ul><li>Convention Over Configuration 约定高于配置  Zend_View  view renderer flexibility has a cost </li></ul><ul><li>D...
Drawbacks of ZF <ul><li>Performance ?  </li></ul><ul><li>Coupling ? </li></ul><ul><li>Complexity?  </li></ul>
Too many files loaded in controllers? Generated by PECL extentsion  Inclued
Too many files loaded in controllers? Xdebug + WinCacheGrind
Opcode cache <ul><li>APC  will be support in PHP6 </li></ul><ul><li>eAccelerator </li></ul><ul><li>Xcache </li></ul><ul><l...
Questions
Thanks MSN: [email_address]
Upcoming SlideShare
Loading in...5
×

Zend Framework

3,471

Published on

General introduction of Zend Framework, an OOP PHP5 Framework we use.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,471
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
40
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Zend Framework"

  1. 1. Zend Framework 陈浩 2008.10.22
  2. 2. <ul><li>陈浩 haohappy </li></ul><ul><li>Chinese Translator of: </li></ul><ul><li>Programming PHP 2 nd edition 《 PHP 程序设计》第二版 </li></ul><ul><li>PHP Objects, Pattens, and Practice 2 nd edition 《 PHP 对象、模式与实践》第二版 </li></ul>About the speaker Member of Zend Framework Documentation Team (Team Lead of the Chinese Team) Translator of PHP Manual
  3. 3. PHP Objects, Patterns and Frameworks <ul><li>PHP4 退出历史舞台, PHP5 成为主流 </li></ul><ul><li>PHP5 对于面向对象的支持大大加强 </li></ul><ul><ul><li>反射( reflection )、异常( exception )、私有和保护( private 和 protected )的方法和属性、 __toString() 方法、 static 修饰符、抽象类和抽象方法、 final 方法和属性、接口、迭代器( iterator )、拦截器( interceptor )方法、类型检查、 const 关键字、引用传递、 __clone() 方法和 __construct() 构造方法等等。 </li></ul></ul><ul><li>面向对象的 PHP 开发 设计模式的应用 </li></ul><ul><li>面向对象的 PHP 开发框架 </li></ul>国内的 FleaPHP, ThinkPHP 等
  4. 4. Contents of this presentation <ul><li>Brief Introduction of ZF </li></ul><ul><li>MVC </li></ul><ul><li>Database </li></ul><ul><li>Useful libs 48 in total </li></ul><ul><ul><li>Web2.0 Dojo, Json, Soap, Rest, XmlRpc, Amf new , Services_*, Gdata </li></ul></ul><ul><ul><li>Generic Auth, Acl, Form, Layout, Cache, Config, Paginator, Mail, Validate, Http </li></ul></ul>
  5. 5. 场景:川菜馆 顾客看菜谱 顾客:来一盘鱼香肉丝 服务员:好咯 服务员告诉大厨: 2 号桌要一盘鱼香肉丝 大厨辛苦劳动。。炒炒炒 搞定。告诉服务员:炒好了。 服务员把菜端给顾客 MVC 的含义 MODEL VIEW CONTROLLER
  6. 6. Zend Framework <ul><li>开放源代码的 PHP5 开发框架 </li></ul><ul><li>易于学习和使用 </li></ul><ul><li>功能强大,促进快速开发 </li></ul><ul><li>有活跃的开发者社区和完善的支持平台 </li></ul><ul><li>BSD 许可 适合商业应用 </li></ul><ul><li>由 Zend 公司主导开发 </li></ul><ul><li>合作: </li></ul>2008 Jolt Award
  7. 8. MVC in ZF Zend_Db_Table Zend_View Zend_Controller
  8. 9. MVC in ZF 单一入口: index.php 项目文件目录分布
  9. 10. Bootstrap ( 入口文件 ) <ul><li><?php //  控制器实例化 $controller =  Zend_Controller_Front :: getInstance (); $controller -> setControllerDirectory ( $controllerDir ); //  设置路由 $router  = new  Zend_Controller_Router_Route_Rewrite (); $controller -> setRouter ( $router ); //  设置请求对象 $request  = new  Zend_Controller_Request_Http (); $controller -> setRequest ( $request ); $controller -> throwExceptions ( true ); $controller -> returnResponse ( true ); //  得到响应对象 $response  =  $controller -> dispatch (); //  输出 echo  $response ; ?> </li></ul>
  10. 11. Zend_Controller
  11. 12. Zend_Controller 用户访问: http://www.phpeye.com/article/view/id/1 Apache Server: url_rewrite 转向所有请求到入口文件 index.php index.php 初始化控制器 Router 对 URL 进行分解 根据路由规则,决定调用哪个 controller 中的哪个 action Dispatcher 调用 controller 中的 action
  12. 13. Zend_Controller <ul><li>Zend_Controller_Front </li></ul><ul><li>设置 controller 目录,生成 request 对象,并 dispatch() </li></ul><ul><li>Zend_Controller_Request_Abstract 默认使用 Zend_Controller_Request_Http </li></ul><ul><li>Zend_Controller_Router_Interface </li></ul><ul><li>决定调用哪个 Controller 中的哪个 Action </li></ul><ul><li>Zend_Controller_Dispatcher_Interface </li></ul><ul><li>调用 controller 中的 Action </li></ul>
  13. 14. Zend_Controller <ul><li>class  ArticleController  extends  Zend_Controller_Action {     public function  indexAction ()     {     } public function viewAction () </li></ul><ul><li>{ $articleId = $this->request-> getParam(‘id’); $article = $this->article->find($articleId); $this->view->article = $article; $this->view->render();// 不需要指定模板 } </li></ul><ul><li>} </li></ul>http://www.phpeye.com/article/ -> indexAction() http://www.phpeye.com/article/view/id/1 -> viewAction()
  14. 15. Model - DB <ul><li>1. 数据库软件的抽象 基于 PDO (PHP Data Objects) </li></ul><ul><ul><ul><li>MySQL, OCI, PostgreSQL, ODBC, DB2, SQLite, Sybase/FreeTDS/MSSQL </li></ul></ul></ul><ul><li>2. SQL 抽象 </li></ul><ul><li>多个层次 </li></ul><ul><li>Zend_Db 手写 Sql $this->db->query($sql); </li></ul><ul><li>Zend_Db_Select 部分手写 </li></ul><ul><li>Zend_Db_Table 基本不用写 Sql </li></ul><ul><li>Zend_Db_Table_Row Row Data Gateway </li></ul><ul><li>Zend_Db_Table_Rowset </li></ul>数据库访问抽象的两个层次
  15. 16. Table Data Gateway <ul><li>An object that acts as a Gateway to a database table. One instance handles all the rows in the table. </li></ul>
  16. 17. Active Record <ul><li>An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data. </li></ul>
  17. 18. CRUD Zend_Db_Table $rows_affected = $this->insert($data); $rows_affected = $this->update($data, $where); $rows_affected = $this->delete($where); $rowset = $this->find($id); Zend_Db $this->db->query($sql);
  18. 19. Zend_View <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title ><?php echo $title ?></title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><?php echo $body ?> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  19. 20. Zend_View <ul><li>PHP is template language itself. You don’t need another one. Just separate your logic from your presentation. </li></ul><ul><li>View Renderer </li></ul><ul><li>Compatible with other template systems, such as Smarty, HTML_Template_PHPLIB, etc. </li></ul>
  20. 21. PHP & Web 2.0
  21. 22. Zend Framework & Web 2.0 <ul><li>Json, Soap, Rest, XmlRpc, Amf new , Dojo, Gdata </li></ul><ul><li>Zend_Services_* 针对某个特定网站的 API 访问客户端 </li></ul><ul><ul><li>Zend_Service_Akismet </li></ul></ul><ul><ul><li>Zend_Service_Amazon </li></ul></ul><ul><ul><li>Zend_Service_Audioscrobbler </li></ul></ul><ul><ul><li>Zend_Service_Delicious </li></ul></ul><ul><ul><li>Zend_Service_Flickr </li></ul></ul><ul><ul><li>Zend_Service_Nirvanix </li></ul></ul><ul><ul><li>Zend_Service_ReCaptcha </li></ul></ul><ul><ul><li>Zend_Service_Simpy </li></ul></ul><ul><ul><li>Zend_Service_SlideShare </li></ul></ul><ul><ul><li>Zend_Service_StrikeIron </li></ul></ul><ul><ul><li>Zend_Service_Technorati </li></ul></ul><ul><ul><li>Zend_Service_Yahoo </li></ul></ul>
  22. 23. Zend Framework & Web 2.0 Json Built-in functions of PHP 5.2 + json_decode() json_encode() <ul><li>Zend_Json </li></ul><ul><li>Json/PHP 数据互相转换 </li></ul><ul><li>服务器端 XML -> Json -> 输出到浏览器 </li></ul><ul><li>JSON-RPC Server 同时支持 Json-rpc v1, v2 规范 </li></ul>Next
  23. 24. Zend Framework & Web 2.0 Json Back
  24. 25. Zend Framework & Web 2.0 Json // fromXml function simply takes a String containing XML contents as input. $jsonContents = Zend_Json::fromXml($xmlStringContents, true); Back
  25. 26. Zend Framework & Web 2.0 Json Back
  26. 27. Zend Framework & Web 2.0 Gdata http://code.google.com/apis/gdata/ <ul><li>Google Calendar </li></ul><ul><li>Google Spreadsheets </li></ul><ul><li>Google Documents List </li></ul><ul><li>Google Provisioning </li></ul><ul><li>Google Base </li></ul><ul><li>YouTube </li></ul><ul><li>Picasa Web Albums </li></ul><ul><li>Google Blogger </li></ul><ul><li>Google CodeSearch </li></ul><ul><li>Google Notebook </li></ul>Zend_Gdata
  27. 28. Zend Framework & Web 2.0 <ul><li>Zend_Services_* 针对某个特定网站的 API 访问客户端 </li></ul><ul><ul><li>Zend_Service_Akismet </li></ul></ul><ul><ul><li>Zend_Service_Amazon </li></ul></ul><ul><ul><li>Zend_Service_Audioscrobbler </li></ul></ul><ul><ul><li>Zend_Service_Delicious </li></ul></ul><ul><ul><li>Zend_Service_Flickr </li></ul></ul><ul><ul><li>Zend_Service_Nirvanix </li></ul></ul><ul><ul><li>Zend_Service_ReCaptcha </li></ul></ul><ul><ul><li>Zend_Service_Simpy </li></ul></ul><ul><ul><li>Zend_Service_SlideShare </li></ul></ul><ul><ul><li>Zend_Service_StrikeIron </li></ul></ul><ul><ul><li>Zend_Service_Technorati </li></ul></ul><ul><ul><li>Zend_Service_Yahoo </li></ul></ul>
  28. 29. Zend Framework & Web 2.0 REST Zend_Rest_Client Zend_Rest_Server
  29. 30. Zend Framework & Web 2.0 REST Zend_Rest_Client $serverUrl = 'http://framework.zend.com/rest'; $client = new Zend_Rest_Client($serverUrl); $result = $client->sayHello('Davey', 'Day') ->get(); if ($result->isSuccess()) {     echo $result; // &quot;Hello Davey, Good Day&quot; }
  30. 31. Zend Framework & Web 2.0 REST Zend_Rest_Client /** * 在 Technorati 上查找某个博客的作者 */ $technoratiUrl = 'http://api.technorati.com/bloginfo'; $technorati = new Zend_Rest_Client( $technoratiUrl); $technorati->key($key); $technorati->url('http://pixelated-dreams.com'); $result = $technorati->get(); echo $result->firstname() .' '. $result->lastname();
  31. 32. Zend Framework & Web 2.0 REST Zend_Rest_Server $server = new Zend_Rest_Server(); $server->setClass('My_Service_Class'); $server->handle(); Class My_Service_Class(){ public function sayHello(){ //return XML here } }
  32. 33. Zend_Amf 支持 Adobe 的 Action Message Format (AMF) 允许浏览器端的 Flash Player 与 PHP 进行通信 . 另外,可以将 Actions Script 中的数据(如对象)方便地转换成 PHP 中的数据。 PHP Flash Server Client
  33. 34. Useful libs <ul><li>Auth, Acl, Form, Layout, Cache, Config, Paginator, Mail, Validate, Http </li></ul>
  34. 35. ZF & RoR <ul><li>Convention Over Configuration 约定高于配置 Zend_View view renderer flexibility has a cost </li></ul><ul><li>Dynamic Helpers For Views 动态的 View Helper </li></ul><ul><li>Generate Components For Application </li></ul><ul><li>自动生成系统部件 Zend_Tool </li></ul>“ I am a giant because I stand on the shoulders of others”
  35. 36. Drawbacks of ZF <ul><li>Performance ? </li></ul><ul><li>Coupling ? </li></ul><ul><li>Complexity? </li></ul>
  36. 37. Too many files loaded in controllers? Generated by PECL extentsion Inclued
  37. 38. Too many files loaded in controllers? Xdebug + WinCacheGrind
  38. 39. Opcode cache <ul><li>APC will be support in PHP6 </li></ul><ul><li>eAccelerator </li></ul><ul><li>Xcache </li></ul><ul><li>Zend Optimizer </li></ul>
  39. 40. Questions
  40. 41. Thanks MSN: [email_address]
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×