Your SlideShare is downloading. ×
  • Like
Zend Framework
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Zend Framework

  • 3,400 views
Published

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

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

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,400
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
39
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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