Foundations of Zend Framework 2
By:
Adam Culp
Twitter: @adamculp
https://joind.in/13239
Foundations of Zend Framework 2
 About me
 PHP 5.3 Certified
 Consultant at Zend Technologies
 Organizer SoFloPHP (Sou...
Foundations of Zend Framework 2
 What is...
 Uses PHP >= 5.3.23
 Open Source
 On GitHub
 Diverse Install
 Pyrus, Com...
Foundations of Zend Framework 2
 Skeleton Application
 Git clone Zendframework Skeleton Application
 Github /zendframew...
Foundations of Zend Framework 2
 Composer
 Update Composer
 php composer.phar self-update
 Install Zend Framework 2
 ...
Foundations of Zend Framework 2
 Composer (easiest)
 Update Composer
 php composer.phar self-update
 Create Project
 ...
Foundations of Zend Framework 2
 Structure
Foundations of Zend Framework 2
 Zend Framework 2 Usage
 NO MAGIC!!!
 Configuration driven
 No forced structure
 Uses...
Foundations of Zend Framework 2
 MVC
 Very briefly
Foundations of Zend Framework 2
 M = Model
 Model = Business Logic, Data
 Models
 Database
 Entities
 Services
Foundations of Zend Framework 2
 V = View
 View = GUI, Presentation, Visual Representation
 HTML
 CSS
 Javascript
 J...
Foundations of Zend Framework 2
 C = Controller
 Controller = Link between a user and the system.
 Places calls to Mode...
Foundations of Zend Framework 2
 Typical Application Flow - Load
 index.php
 Loads autoloader (PSR-0 = default)
 init ...
Foundations of Zend Framework 2
 Typical Application Flow – App Config
 application.config.php
 Loads modules one at a ...
Foundations of Zend Framework 2
 Modules
 Related for a specific “problem”.
 Logical separation of application function...
Foundations of Zend Framework 2
 Module
 Contents
 PHP Code
 MVC Functionality
 Library Code
 Though better in Appli...
Foundations of Zend Framework 2
 Modules
 Easy creation using Zend Skeleton Module
 GitHub /zendframework/ZendSkeletonM...
Foundations of Zend Framework 2
 Typical Application Flow – Modules
 Module.php (convention)
 Makes MvcEvent accessible...
Foundations of Zend Framework 2
 Typical Application Flow – Module Config
 module.config.php
 Containers are component ...
Foundations of Zend Framework 2
 Routes
 Carries how controller maps to request
 Types:
 Hostname – 'me.adamculp.com'
...
Foundations of Zend Framework 2
 Route Example
/module/Application/config/module.config.php
Foundations of Zend Framework 2
 Navigation and Sitemaps (optional)
 Driven by configuration.
/module/Application/config...
Foundations of Zend Framework 2
 Navigation and Sitemaps (optional)
 Use in Layout or View.
/module/Application/view/lay...
Foundations of Zend Framework 2
 Database
 3 different ways to interact with data:
 DB
 Select
 Table Gateway
 Or us...
Foundations of Zend Framework 2
 Services
 ALL THE THINGS!
Foundations of Zend Framework 2
 ServiceManager
 Recommended alternative to ZendDi
 Di pure DIC, SM is factory-based co...
Foundations of Zend Framework 2
 Service Sample
/module/Application/config/module.config.php
Foundations of Zend Framework 2
 Service Usage
/module/Application/Module.php
/module/Application/view/layout/layout.phtml
Foundations of Zend Framework 2
 Services
 Types:
 Explicit (name => object pairs)
 Invokables (name => class to insta...
Foundations of Zend Framework 2
 Event Manager
 Triggers events
 Listen and react to triggered events
 Object that agg...
Foundations of Zend Framework 2
 Diagram of MVC Events
Foundations of Zend Framework 2
 Events
 Everything is an event
 loadModule(s)
 .resolve, .post
 bootstrap
 route
 ...
Foundations of Zend Framework 2
 Event Sample
/module/Application/Module.php
Foundations of Zend Framework 2
 Views
 Directory Structure
Foundations of Zend Framework 2
 Views
 View Model
 Array carrying info to the view.
 Automatically created, unless cr...
Foundations of Zend Framework 2
 Forms Sample
 Create elements
/module/Products/src/Products/Form/ProductSearchForm.php
Foundations of Zend Framework 2
 Forms Sample
 Pass the form to view
/module/Products/src/Products/Controller/ProductsCo...
Foundations of Zend Framework 2
 Forms Sample
 Output form in view
/module/Products/view/products/products/search.phtml
Foundations of Zend Framework 2
 REST
 AbstractRestfulController
 Parsing JSON request bodies
 View not needed (with J...
Foundations of Zend Framework 2
 REST Sample
 Create Route
/module/ProductsRest/config/module.config.php
Foundations of Zend Framework 2
 REST Sample
 Apply Json View Strategy
/module/ProductsRest/config/module.config.php
Foundations of Zend Framework 2
 REST Sample
 Create result as JsonModel
 No view files needed, outputs JSON
/module/Pr...
Foundations of Zend Framework 2
 Apigility.org
 Ensures well-formed API
 Dev does less work
Foundations of Zend Framework 2
 Resources
 http://framework.zend.com
 http://www.zend.com/en/services/training/course-...
Foundations of Zend Framework 2
 Thank You!
 Speaker: Adam Culp
 Twitter: @adamculp
 Rate this talk: https://joind.in/...
Upcoming SlideShare
Loading in...5
×

Foundations of Zend Framework_2

1,966

Published on

For this talk Adam Culp will cover a basic intro to Zend Framework 2 (ZF2) and how to use the foundational pieces. We will discover how to get a Zend Framework 2 application up and running quickly using GitHub, Composer, and the Zend Framework 2 Skeleton Application. Then we will leverage the Zend Skeleton Module to introduce adding modules to a Zend Framework 2 application.

We will also cover basic usage of the ZF2 module manager, event manager, service manager, and database components. Adam will also introduce some useful resources to help attendees continue learning on their own. The goal of the talk is to give attendees enough information to be able to get a jump start into using ZF2.

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

No Downloads
Views
Total Views
1,966
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Foundations of Zend Framework_2

  1. 1. Foundations of Zend Framework 2 By: Adam Culp Twitter: @adamculp https://joind.in/13239
  2. 2. Foundations of Zend Framework 2  About me  PHP 5.3 Certified  Consultant at Zend Technologies  Organizer SoFloPHP (South Florida)  Organizer SunshinePHP (Miami)  Long Distance (ultra) Runner  Judo Black Belt Instructor
  3. 3. Foundations of Zend Framework 2  What is...  Uses PHP >= 5.3.23  Open Source  On GitHub  Diverse Install  Pyrus, Composer, Git Submodules  Built on MVC design pattern  Can be used as components or entire framework
  4. 4. Foundations of Zend Framework 2  Skeleton Application  Git clone Zendframework Skeleton Application  Github /zendframework/ZendSkeletonApplication
  5. 5. Foundations of Zend Framework 2  Composer  Update Composer  php composer.phar self-update  Install Zend Framework 2  php composer.phar install  Creates and/or populates '/vendor' directory  Clones Zend Framework 2  Sets up Composer autoloader (PSR-0)
  6. 6. Foundations of Zend Framework 2  Composer (easiest)  Update Composer  php composer.phar self-update  Create Project  php composer create-project zendframework/skeleton-application
  7. 7. Foundations of Zend Framework 2  Structure
  8. 8. Foundations of Zend Framework 2  Zend Framework 2 Usage  NO MAGIC!!!  Configuration driven  No forced structure  Uses namespaces
  9. 9. Foundations of Zend Framework 2  MVC  Very briefly
  10. 10. Foundations of Zend Framework 2  M = Model  Model = Business Logic, Data  Models  Database  Entities  Services
  11. 11. Foundations of Zend Framework 2  V = View  View = GUI, Presentation, Visual Representation  HTML  CSS  Javascript  JSON  XML  NO BUSINESS LOGIC!
  12. 12. Foundations of Zend Framework 2  C = Controller  Controller = Link between a user and the system.  Places calls to Model layer.  Passes needed info to the View layer.
  13. 13. Foundations of Zend Framework 2  Typical Application Flow - Load  index.php  Loads autoloader (PSR-0 = default)  init Application using application.config.php
  14. 14. Foundations of Zend Framework 2  Typical Application Flow – App Config  application.config.php  Loads modules one at a time  (Module.php = convention)  Specifies where to find modules  Loads configs in autoload directory (DB settings, etc.)
  15. 15. Foundations of Zend Framework 2  Modules  Related for a specific “problem”.  Logical separation of application functionality  Reusable  Removing a module doesn't kill the application  By convention modules are found in:  Modules directory  Vendor directory  Contains everything specific to given module
  16. 16. Foundations of Zend Framework 2  Module  Contents  PHP Code  MVC Functionality  Library Code  Though better in Application or via Composer  May not be related to MVC  View scripts  Public assets (images, css, javascript)  More?
  17. 17. Foundations of Zend Framework 2  Modules  Easy creation using Zend Skeleton Module  GitHub /zendframework/ZendSkeletonModule
  18. 18. Foundations of Zend Framework 2  Typical Application Flow – Modules  Module.php (convention)  Makes MvcEvent accessible via onBootstrap()  Giving further access to Application, Event Manager, and Service Manager.  Loads module.config.php  Specifies autoloader and location of files.  May define services and wire event listeners as needed.
  19. 19. Foundations of Zend Framework 2  Typical Application Flow – Module Config  module.config.php  Containers are component specific  Routes  Navigation  Service Manager  Translator  Controllers  View Manager  Steer clear of Closures (Anonymous Functions)  Do not cache well within array.  Less performant (parsed and compiled on every req) as a factory only parsed when service is used.
  20. 20. Foundations of Zend Framework 2  Routes  Carries how controller maps to request  Types:  Hostname – 'me.adamculp.com'  Literal - '/home'  Method – 'post,put'  Part – creates a tree of possible routes  Regex – use regex to match url '/blog/?<id>[0-9]?'  Scheme – 'https'  Segment - '/:controller[/:action][/]'  Query – specify and capture query string params
  21. 21. Foundations of Zend Framework 2  Route Example /module/Application/config/module.config.php
  22. 22. Foundations of Zend Framework 2  Navigation and Sitemaps (optional)  Driven by configuration. /module/Application/config/module.config.php
  23. 23. Foundations of Zend Framework 2  Navigation and Sitemaps (optional)  Use in Layout or View. /module/Application/view/layout/layout.phtml
  24. 24. Foundations of Zend Framework 2  Database  3 different ways to interact with data:  DB  Select  Table Gateway  Or use an ORM of your choosing
  25. 25. Foundations of Zend Framework 2  Services  ALL THE THINGS!
  26. 26. Foundations of Zend Framework 2  ServiceManager  Recommended alternative to ZendDi  Di pure DIC, SM is factory-based container (no magic, code explicitly details how instance created)  Can be created from:  Application configuration  Module classes  Module configuration  Local override configuration  Everything is a service, even Controllers (though provided by ControllerManager)
  27. 27. Foundations of Zend Framework 2  Service Sample /module/Application/config/module.config.php
  28. 28. Foundations of Zend Framework 2  Service Usage /module/Application/Module.php /module/Application/view/layout/layout.phtml
  29. 29. Foundations of Zend Framework 2  Services  Types:  Explicit (name => object pairs)  Invokables (name => class to instantiate)  Factories (name => callable returning object)  Aliases (name => some other name)  Abstract Factories (unknown services)  Scoped Containers (limit what can be created)  Shared (or not; you decide)
  30. 30. Foundations of Zend Framework 2  Event Manager  Triggers events  Listen and react to triggered events  Object that aggregates listeners  Listener is a callback that can react to an event  Event is an action
  31. 31. Foundations of Zend Framework 2  Diagram of MVC Events
  32. 32. Foundations of Zend Framework 2  Events  Everything is an event  loadModule(s)  .resolve, .post  bootstrap  route  dispatch  dispatch.error  render  render.error  finish  sendResponse
  33. 33. Foundations of Zend Framework 2  Event Sample /module/Application/Module.php
  34. 34. Foundations of Zend Framework 2  Views  Directory Structure
  35. 35. Foundations of Zend Framework 2  Views  View Model  Array carrying info to the view.  Automatically created, unless created specifically.  Hold Variable Containers for use in the View. /module/Application/Module.php /module/Application/view/layout/layout.phtml
  36. 36. Foundations of Zend Framework 2  Forms Sample  Create elements /module/Products/src/Products/Form/ProductSearchForm.php
  37. 37. Foundations of Zend Framework 2  Forms Sample  Pass the form to view /module/Products/src/Products/Controller/ProductsController.php
  38. 38. Foundations of Zend Framework 2  Forms Sample  Output form in view /module/Products/view/products/products/search.phtml
  39. 39. Foundations of Zend Framework 2  REST  AbstractRestfulController  Parsing JSON request bodies  View not needed (with Json View Strategy)  Contains methods to handle get, post, put, delete  Extend as needed
  40. 40. Foundations of Zend Framework 2  REST Sample  Create Route /module/ProductsRest/config/module.config.php
  41. 41. Foundations of Zend Framework 2  REST Sample  Apply Json View Strategy /module/ProductsRest/config/module.config.php
  42. 42. Foundations of Zend Framework 2  REST Sample  Create result as JsonModel  No view files needed, outputs JSON /module/ProductsRest/src/Controller/ProductsController.php
  43. 43. Foundations of Zend Framework 2  Apigility.org  Ensures well-formed API  Dev does less work
  44. 44. Foundations of Zend Framework 2  Resources  http://framework.zend.com  http://www.zend.com/en/services/training/course-catal og/zend-framework-2  http://www.zend.com/en/services/training/course-cata log/zend-framework-2-advanced  http://zendframework2.de/cheat-sheet.html  http://apigility.org
  45. 45. Foundations of Zend Framework 2  Thank You!  Speaker: Adam Culp  Twitter: @adamculp  Rate this talk: https://joind.in/13239  Code: https://github.com/adamculp/foundations-zf2-talk

×