Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zend Framework 101 (ZF1)

Zend Framework 101 (ZF1)

Intro to ZF1

Shaun Farrell

January 01, 2010
Tweet

More Decks by Shaun Farrell

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. General Structure Controllers Models Configuration Files Layouts Views Forms Modules

    Public Folder - Font Controller Library Services Thursday, July 21, 11
  4. Views Display templates. No Logic in here There are helper

    methods like partialLoop, baseUrl etc.. Thursday, July 21, 11
  5. 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
  6. Controllers How the request is controlled. Controllers have actions indexAction(),

    bookAction(), authorAction() Fat vs Skinny Move Logic to Service Classes Thursday, July 21, 11
  7. Configs Store application specific configurations Loaded at request via FrontController

    Custom Configs Vs Resource configs Thursday, July 21, 11
  8. Layouts View Templates Can have as many as you want

    Like Master Templates in .net Thursday, July 21, 11
  9. 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
  10. 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
  11. Library Location of ZF Libs and other Libs. Custom Libraries

    - Keep same format. Thursday, July 21, 11
  12. Services Auto-loaded by Zend_Autoloader Can be used for anything. Example

    Usage - Image Classes, other Common scripts. Thursday, July 21, 11
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. MVC Separation of Code. Splits the user interface interaction into

    three distinct roles. http://martinfowler.com/eaaCatalog/ modelViewController.html Thursday, July 21, 11
  19. 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
  20. 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
  21. Front Controller A controller handles all the request for a

    web site. http://martinfowler.com/eaaCatalog/ frontController.html Thursday, July 21, 11
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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
  35. 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
  36. 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
  37. 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
  38. 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
  39. 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
  40. 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
  41. 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