Slide 1

Slide 1 text

Zend Framework 101 Shaun Farrell Thursday, July 21, 11

Slide 2

Slide 2 text

Zend Framework (ZF) Open-Source Software (OSS) New BSD License Contributor License Agreement (CLA) Zend Technologies Development Started in Summer 2005 0.1.0 Released in March 2006 1.11.9 Released in July 2011 Thursday, July 21, 11

Slide 3

Slide 3 text

Fully Object-Oriented (PHP5) Requires PHP 5.2.4 or Later Use-at-Will Architecture Loosely Coupled Components Component vs Full Stack Framework Coding Standards, Code Coverage (80%) 80% of common tasks, 20% Business Logic Thursday, July 21, 11

Slide 4

Slide 4 text

ZF Structure Thursday, July 21, 11

Slide 5

Slide 5 text

General Structure Controllers Models Configuration Files Layouts Views Forms Modules Public Folder - Font Controller Library Services Thursday, July 21, 11

Slide 6

Slide 6 text

Views Display templates. No Logic in here There are helper methods like partialLoop, baseUrl etc.. Thursday, July 21, 11

Slide 7

Slide 7 text

Models Model folder is Auto-loaded by Zend_Application. DbTable and Mappers are also auto-loaded. Data Mapper Design Pattern There is no Zend_Model OO Classes! Thursday, July 21, 11

Slide 8

Slide 8 text

Controllers How the request is controlled. Controllers have actions indexAction(), bookAction(), authorAction() Fat vs Skinny Move Logic to Service Classes Thursday, July 21, 11

Slide 9

Slide 9 text

Configs Store application specific configurations Loaded at request via FrontController Custom Configs Vs Resource configs Thursday, July 21, 11

Slide 10

Slide 10 text

Layouts View Templates Can have as many as you want Like Master Templates in .net Thursday, July 21, 11

Slide 11

Slide 11 text

Forms Class structured Uses Zend_Form Thursday, July 21, 11

Slide 12

Slide 12 text

Modules Separation of your Application Default Module vs No Default Module Recommend Default Module Can have as many as you want Can use or share other Models etc. Uncouple them! Thursday, July 21, 11

Slide 13

Slide 13 text

Public Folder - FC Holds your Front Controller All requests come in through Index.php Public folder is your Web root! Put assets here (css, images, js etc.) Thursday, July 21, 11

Slide 14

Slide 14 text

Library Location of ZF Libs and other Libs. Custom Libraries - Keep same format. Thursday, July 21, 11

Slide 15

Slide 15 text

Services Auto-loaded by Zend_Autoloader Can be used for anything. Example Usage - Image Classes, other Common scripts. Thursday, July 21, 11

Slide 16

Slide 16 text

Modules Blog example.com/blog Default example.com/ Thursday, July 21, 11

Slide 17

Slide 17 text

ZF Routing Thursday, July 21, 11

Slide 18

Slide 18 text

Everything comes in through index.php in your public folder This is your FrontController FrontController loads your Configs and then Runs Zend_Application which auto-loads everything Then the request is dispatched out to the correct module/controller/action or route. It’s not that simple! Thursday, July 21, 11

Slide 19

Slide 19 text

dsd Plugin Call:RouteStartup Routing CreateStd.ResponseObject Zend_Controller_Response_Http CreateStd.RequestObject Zend_Controller_Request_Http Also registered inPlugin Broker Plugin Call:RouteShutdown Plugin Call:dispatchLoopStartup Sendcollated content from ResponseObject Plugin Call:dispatchLoopShutdown Plugin Call:postDispatch While RequestObject notdispatched (==false) do Setdispatched =true inRequestObject Plugin Call:preDispatch IsRequestObject reseted through apreDispatch Plugin? Yes ActionControllerDispatch Process Plugin Call ReadMethod and Actionfrom RequestObject CreateInstanceof the appropiate ActionController. Constructor of Zend_Controller_Action creates Zend_Controller_Action_HelperBroker. Setdispatched =true inRequestObject CallActionController's dispatch()method (Passesthe Nameof Actionto the Method) OutputinBuffer: ob_start() Writebuffered output to the Responseobject using appendBody() Destroy ActionControllerObject Zend_Controller_Dispatcher_Standard Zend_Controller_FrontͲ>dispatch() Helper Call:PreDispatch Helper Call:PostDispatch CallpreDispatch() isDispatched()==true? No Callof the ActionMethod CallpostDispatch() Helper Call V1.01,Created by ThorstenRuf Zend_Controller_ActionͲ>dispatch() Set‚default‘Route (if notpresent) Extract Module,Controller, Actionand Parametersfrom URL Standard:Zend_Controller_Router_Rewrite FindmatchingRoute (whichRoutematchesthe URL,LastͲInͲFirstͲOut Principle) WriteModule,Controller,Action andallParametersintothe RequestObject SetActionControllerInstanceinallActionHelpers (loop) Zend_Controller_Action_HelperBrokerͲ>__construct() CallInit()methods of allregisteredHelpers registeredinthe Broker Try– CatchBlock Dispatch Process Overview Thursday, July 21, 11

Slide 20

Slide 20 text

FC handles incoming request Router maps urls to module, controller, action Dispatcher dispatches the request Action controller runs logic Request passed to request object Output response Thursday, July 21, 11

Slide 21

Slide 21 text

Logic can be run at multiple points in a dispatch! Thursday, July 21, 11

Slide 22

Slide 22 text

FrontController Plugins routeStartup() is called before Zend_Controller_Front calls on the router to evaluate the request against the registered routes. routeShutdown() is called after the router finishes routing the request. dispatchLoopStartup() is called before Zend_Controller_Front enters its dispatch loop. preDispatch() is called before an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via Zend_Controller_Request_Abstract::setDispatched(false)), the current action may be skipped and/or replaced. postDispatch() is called after an action is dispatched by the dispatcher. This callback allows for proxy or filter behavior. By altering the request and resetting its dispatched flag (via Zend_Controller_Request_Abstract::setDispatched(false)), a new action may be specified for dispatching. dispatchLoopShutdown() is called after Zend_Controller_Front exits its dispatch loop. Thursday, July 21, 11

Slide 23

Slide 23 text

Standard Router :controller/:action http://www.loc.gov/pictures/collections/ Would load pictures controller, and collections action :module/:controller/:action http://www.loc.gov/admin/pictures/add Would load admin module, pictures controller, and add action Thursday, July 21, 11

Slide 24

Slide 24 text

Custom Routes Zend_Controller_Router_Route Zend_Controller_Router_Route_Static Zend_Controller_Router_Route_Regex Zend_Controller_Router_Route_Hostname Zend_Controller_Router_Route_Chain Zend_Controller_Router_Rewrite http://framework.zend.com/manual/en/ zend.controller.router.html Thursday, July 21, 11

Slide 25

Slide 25 text

ZF Design Patterns (JUST A FEW) Thursday, July 21, 11

Slide 26

Slide 26 text

MVC Separation of Code. Splits the user interface interaction into three distinct roles. http://martinfowler.com/eaaCatalog/ modelViewController.html Thursday, July 21, 11

Slide 27

Slide 27 text

Data Mapper A layer of mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself http://martinfowler.com/eaaCatalog/ dataMapper.html Thursday, July 21, 11

Slide 28

Slide 28 text

Table Data Gateway An object that acts as a “Gateway” to a database table. One instance handles all the rows in the table. Table Data Gateway Vs. Data Mapper http://martinfowler.com/eaaCatalog/ tableDataGateway.html Thursday, July 21, 11

Slide 29

Slide 29 text

Front Controller A controller handles all the request for a web site. http://martinfowler.com/eaaCatalog/ frontController.html Thursday, July 21, 11

Slide 30

Slide 30 text

Composite View & Two Step View 2 Step - Turns domain data into HTML in two steps: first by forming some kin of logical page, then rendering the logical page into HTML. Layouts & Views Thursday, July 21, 11

Slide 31

Slide 31 text

Decorators Allows you to dynamically add behavior to an existing object. Zend_Form - changing the markup. http://en.wikipedia.org/wiki/Decorator_pattern Thursday, July 21, 11

Slide 32

Slide 32 text

Martin Fowler P of EAA http:// martinfowler.com/ Thursday, July 21, 11

Slide 33

Slide 33 text

Recommended Practices Thursday, July 21, 11

Slide 34

Slide 34 text

Follow ZF Coding Standards http://framework.zend.com/manual/en/coding- standard.html Never use private visibility All components can be extended! Extend them in your Library Thursday, July 21, 11

Slide 35

Slide 35 text

Getting Started Thursday, July 21, 11

Slide 36

Slide 36 text

Zend Tool Quickly Generate project components Command Line Tools http://zfcampus.org/ - ZF Pear Channel > zf create project . > zf create controller Library 1 default Quick Demo Thursday, July 21, 11

Slide 37

Slide 37 text

ZF Components Thursday, July 21, 11

Slide 38

Slide 38 text

Lightweight Access Control List. Made up of Resources and Roles. You can define what they are (controllers, actions, modules, etc.) Roles request access to a resource. http://framework.zend.com/manual/en/ zend.acl.introduction.html Zend_Acl Thursday, July 21, 11

Slide 39

Slide 39 text

Zend_Auth Allows for Authentication not Authorization! Many Adapters Uses Singleton Pattern - Zend_Auth::getInstance() http://framework.zend.com/manual/en/ zend.auth.introduction.html Thursday, July 21, 11

Slide 40

Slide 40 text

Generic way to cache any data Frontend and Backend Caching frontend - output, function, classes, file, page. backend - file, sqlite, memchached, libmemcached, apc, xcache, ZendServer Caching http://framework.zend.com/manual/en/ zend.cache.html Zend_Cache Thursday, July 21, 11

Slide 41

Slide 41 text

Zend_Date Detailed, but simple API for manipulating dates and times. Use Caution or just use PHP DateTime http://framework.zend.com/manual/en/ zend.date.introduction.html Thursday, July 21, 11

Slide 42

Slide 42 text

Zend_Db Databases Interfaces via adapters IBM DB2, MariaDB, MySQL, SQL Server, Oracle, PostgreSQL, SQLite. http://framework.zend.com/manual/en/ zend.db.html Thursday, July 21, 11

Slide 43

Slide 43 text

Zend_Http Simple Interface to perform HTTP requests Allows for Simple and complex requests like HTTP Auth & File uploads. http://framework.zend.com/manual/en/ zend.http.client.html Thursday, July 21, 11

Slide 44

Slide 44 text

Zend_Json Convenience methods for serializing Native PHP to JSON and vice versa. encode, decode, prettyPrint, XML->JSON http://framework.zend.com/manual/en/ zend.json.html Thursday, July 21, 11

Slide 45

Slide 45 text

Zend_Log General purpose logging classes. Log, Writers, Filters, and Formatters. Writters Streams, Database, Firebug http://framework.zend.com/manual/en/ zend.log.html Thursday, July 21, 11

Slide 46

Slide 46 text

Zend_Locale Set the Locale the User may be in so that display info can be displayed correctly based on locality. Base backend support class. Works with Zend_ Translate, Date, Calendar, Currency, Measure, etc.... http://framework.zend.com/manual/en/ zend.locale.html Thursday, July 21, 11

Slide 47

Slide 47 text

Zend_Translate Solution for multilingual applications Adapters Array, CSV, Gettext, ini, Tbx, Tmx, Qt, Xliff, XmlTm. http://framework.zend.com/manual/en/ zend.translate.html Thursday, July 21, 11

Slide 48

Slide 48 text

Zend_Measure Working with measurements units Based on Locale Allows for creation, conversion, add, subtract, compare. http://framework.zend.com/manual/en/ zend.measure.html Thursday, July 21, 11

Slide 49

Slide 49 text

Zend_Navigation Component for managing trees of pointers to web pages. Can be used for menus, breadcrumbs, links, Sitemaps, etc.. XML, Array, Config files, etc. http://framework.zend.com/manual/en/ zend.navigation.html Thursday, July 21, 11

Slide 50

Slide 50 text

Zend_Paginator Flexible component for paginating collections of data. Adapters Array, DbSelect, DbTableSelect, Iterator, Null Use custom routes with pagination. Use Zend_Db_Select with lots of data http://framework.zend.com/manual/en/ zend.paginator.html Thursday, July 21, 11

Slide 51

Slide 51 text

Zend_Service Service libraries for 3rd party applications Twitter, Amazon EC2, S3, SQS, Ebay, WindowsAzure, Yahoo. Slideshare, etc. http://framework.zend.com/manual/en/ zend.service.html Thursday, July 21, 11

Slide 52

Slide 52 text

Future Thursday, July 21, 11

Slide 53

Slide 53 text

Zend Framework 2.0 Native PHP 5.3 Namespaces, Closures, Late Static Binding, etc. Will break backwards compatibility. In Development now - Began Feb 2010. Currently on Development Release #3. Roadmap - http://framework.zend.com/wiki/display/ZFDEV2/Zend +Framework+2.0+Roadmap GitHub - https://github.com/zendframework/zf2 Thursday, July 21, 11

Slide 54

Slide 54 text

Resources Thursday, July 21, 11

Slide 55

Slide 55 text

http://framework.zend.com Reference Guide, Tutorial (Model/Mapper) http://akrabat.com/ - Tutorial Google IRC - #zftalk #zftalk.dev Mailing Lists - http://framework.zend.com/wiki/display/ZFDEV/ Contributing+to+Zend+Framework Search Github for Code Search Slideshare for Zend Framework Thursday, July 21, 11