SlideShare a Scribd company logo
John Coggeshall
Hi! I’m John! 
• Involved in PHP since circa 1996 
• Sr. Architect, Zend Global Services 
• PHP Core Contributor 
• ZF Contributor
Introduction to ZF2 
 In this talk we’re going to look over the key 
components of any ZF2 application 
• The Model, View, and Controller architecture 
• The Module Architecture 
• Service Manager 
• Event Manager
Getting Started 
 The easiest way to get started in ZF2 is to 
start with the skeleton application: 
https://github.com/zendframework/zendskeletonapplication 
$ composer create-project  
-sdev  
-repository-url=“https://packages.zendframework.com”  
zendframework/skeleton-application  
/path/to/install
Basic ZF2 File structure 
 config/ - Application 
Config 
 module/ - Application 
modules 
 public/ - Docroot for 
images, css, etc.
ZF2 Modules 
 In ZF2 modules are a core concept when 
developing applications. Everything including 
the application is a module. 
 Modules can be application-specific or can be 
written generically and then loaded into the 
application via composer
How do Modules work? 
 Every ZF2 module starts with a Module class 
which describes the module and the things it 
provides to the application 
 Services 
 Event Handlers 
 Controllers 
 Routes 
 Etc.
How do Modules work? 
 Modules also have their own configuration 
files which can setup default values that are 
later over-written by the application’s 
configurations. 
 Useful for creating module-specific routes, or 
module-specific configurations, etc. 
 config/module.config.php
How do Modules work? 
 The module class can implement a number of 
useful methods 
 getAutoLoaderConfig() – configure the way 
classes are autoloaded through this module 
 getServiceConfig() – set up the way services this 
module provides can be created and accessed 
 getModuleDependencies() – Define module 
dependencies 
 onBootstrap() – Executed when module is fired up
How are modules structured?
ZF2 MVC 
 In ZF2, the MVC architecture is entirely driven 
by the events (ZendMvcMvcEvent) 
 Bootstrap 
 Dispatch 
 Dispatch Error 
 Finish 
 Render 
 Render Error 
 Route
ZF2 MVC 
 Typically you don’t have to worry too much 
about these things, as the basic MVC takes 
care of things for you 
 You define routes in the application config which 
map to controllers / actions 
 These controller / actions get executed and return 
a result 
 This result is passed to the View component to be 
rendered
ZF2 MVC 
 Events are useful however because they allow 
you to augment or short-circuit the default 
behavior 
 I.e. Catch the dispatch event and make sure the 
user is authenticated 
 I.e. Catch the dispatch error and render error 
events to do custom logging
Service Manager 
 MVC, and ZF2 applications in general rely 
heavily on something called the Service 
Manager to deal with application 
dependencies 
 Examples: The DB adapter used by the 
application is created by the Service Manager
Service Manager 
 Implementing dependencies and 
components as services allows modules to be 
completely decoupled from each other 
 Services are identified by unique ID, which is 
referenced when the service is required 
 Customization (i.e. a different DB adapter) 
can be done simply by over-writing the 
factory associated with that unique ID
Service Manager 
 In a module services can be defined in various 
locations 
 module.config.php (the ‘service_manager’ key) 
 Module::getServiceConfig() (the programatic 
approach)
Service Manager 
 How services can be defined 
 By factory – identify the key to either a class that 
implements a Factory interface or other callable 
which returns the instance 
 By invokable – Simply identify the class associated 
with this service 
 Aliases – Services can have an alias for 
complicated dependency scenarios
Working with Routes 
 Routes are one of the first things done in 
MVC 
 Goal – Match a given URL to something 
actionable 
 Examples 
 Literal Route (i.e. /exactly/this) 
 Segment Route (i.e. /articles[/:article_id]) 
 RegEx (i.e. /blog/(?<id>[a-zA-Z0-9_-]+)
Working with Routes 
 Below is an example simple route
Controllers 
 When a route is matched, a dispatch event is 
fired, and the corresponding controller/action 
is executed 
 The controller is loaded via service manager 
(allowing for dependency injection) 
 Controller action is called and one of two things 
can be returned 
 A Response object 
 An array or instance of the ViewModel class
Summary 
 This is a very surface-level exploration into 
the complex possibilities of ZF2, but enough 
to get started. 
 Get to know Service Manager and Event 
Manager very well and they will serve you 
fantastically, allowing you to write powerful 
reusable components
Any questions? 
Slides will be available at http://www.slideshare.net/coogle

More Related Content

PDF
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
PDF
SpringMVC
PDF
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
PPTX
5 angularjs features
PDF
AngularJS with RequireJS
PPTX
Angular js 2.0 beta
PPTX
PDF
Angularjs - lazy loading techniques
Встреча №9. Будущее паттерна MVVM в iOS приложениях, Денис Лебедев
SpringMVC
«ReactiveCocoa и MVVM» — Николай Касьянов, SoftWear
5 angularjs features
AngularJS with RequireJS
Angular js 2.0 beta
Angularjs - lazy loading techniques

What's hot (20)

PPTX
AngularJS 2.0
PPTX
Mule testing
PPTX
MUnit run and wait scope
PDF
AngularJS 2.0 Jumpstart
PPTX
Mule java part-1
ODP
Introduction to Angular 2
ODP
Microservices in a netshell
PPTX
Mule java part-1
PDF
AngularJS: Overview & Key Features
PPTX
Deploying and Running in Mule
PPTX
Java in mule part 1
PDF
Workshop 2: JavaScript Design Patterns
PDF
Angular 2: core concepts
PDF
AngularJS introduction
PDF
AngularJS 101 - Everything you need to know to get started
PPTX
Front end development with Angular JS
PDF
Angular js
PDF
Tech Webinar: Angular 2, Introduction to a new framework
PPTX
Using maven with mule
PDF
Angular from Scratch
AngularJS 2.0
Mule testing
MUnit run and wait scope
AngularJS 2.0 Jumpstart
Mule java part-1
Introduction to Angular 2
Microservices in a netshell
Mule java part-1
AngularJS: Overview & Key Features
Deploying and Running in Mule
Java in mule part 1
Workshop 2: JavaScript Design Patterns
Angular 2: core concepts
AngularJS introduction
AngularJS 101 - Everything you need to know to get started
Front end development with Angular JS
Angular js
Tech Webinar: Angular 2, Introduction to a new framework
Using maven with mule
Angular from Scratch
Ad

Similar to Introduction to Zend Framework 2 (20)

PPTX
ZF2 Modules: Events, Services, and of course, modularity
PDF
Deprecated: Foundations of Zend Framework 2
PDF
Foundations of Zend Framework
PDF
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
PDF
ZF2 Modular Architecture - Taking advantage of it
PPT
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
PPTX
JavaScript Module Loaders
PDF
PPTX
Angular modules in depth
PPTX
Soft serve prism
PDF
Spring mvc
PDF
Unit 07: Design Patterns and Frameworks (1/3)
PPT
Zend framework 02 - mvc
PDF
Mvc interview questions – deep dive jinal desai
ODP
Angularjs
PPTX
Composite Application Library, Prism v2
PDF
Setup ColdFusion application using fusebox mvc architecture
PPTX
MVC & backbone.js
PPT
2007 Zend Con Mvc
PDF
MuleSoft Surat Live Demonstration Virtual Meetup#3 - Building JWT OAuth 2.0 C...
ZF2 Modules: Events, Services, and of course, modularity
Deprecated: Foundations of Zend Framework 2
Foundations of Zend Framework
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
ZF2 Modular Architecture - Taking advantage of it
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
JavaScript Module Loaders
Angular modules in depth
Soft serve prism
Spring mvc
Unit 07: Design Patterns and Frameworks (1/3)
Zend framework 02 - mvc
Mvc interview questions – deep dive jinal desai
Angularjs
Composite Application Library, Prism v2
Setup ColdFusion application using fusebox mvc architecture
MVC & backbone.js
2007 Zend Con Mvc
MuleSoft Surat Live Demonstration Virtual Meetup#3 - Building JWT OAuth 2.0 C...
Ad

More from John Coggeshall (20)

PPTX
Virtualization for Developers
PPTX
Migrating to PHP 7
PPTX
Peek at PHP 7
PPT
PHP Development for Google Glass using Phass
PPTX
Virtualization for Developers
PPTX
Development with Vagrant
PPTX
10 things not to do at a Startup
PPTX
Virtualization for Developers
PPTX
PPT
Building PHP Powered Android Applications
PPT
Ria Applications And PHP
PPT
Beyond the Browser
PPT
Apache Con 2008 Top 10 Mistakes
PPT
Ria Development With Flex And PHP
PPT
Top 10 Scalability Mistakes
PPT
Enterprise PHP: A Case Study
PPT
Building Dynamic Web Applications on i5 with PHP
PPT
PHP Security Basics
PPT
Migrating from PHP 4 to PHP 5
PPT
Ajax and PHP
Virtualization for Developers
Migrating to PHP 7
Peek at PHP 7
PHP Development for Google Glass using Phass
Virtualization for Developers
Development with Vagrant
10 things not to do at a Startup
Virtualization for Developers
Building PHP Powered Android Applications
Ria Applications And PHP
Beyond the Browser
Apache Con 2008 Top 10 Mistakes
Ria Development With Flex And PHP
Top 10 Scalability Mistakes
Enterprise PHP: A Case Study
Building Dynamic Web Applications on i5 with PHP
PHP Security Basics
Migrating from PHP 4 to PHP 5
Ajax and PHP

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
L1 - Introduction to python Backend.pptx
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
AI in Product Development-omnex systems
PPT
Introduction Database Management System for Course Database
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Odoo POS Development Services by CandidRoot Solutions
Operating system designcfffgfgggggggvggggggggg
ManageIQ - Sprint 268 Review - Slide Deck
How Creative Agencies Leverage Project Management Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
L1 - Introduction to python Backend.pptx
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Nekopoi APK 2025 free lastest update
AI in Product Development-omnex systems
Introduction Database Management System for Course Database
Design an Analysis of Algorithms I-SECS-1021-03
Introduction to Artificial Intelligence
Which alternative to Crystal Reports is best for small or large businesses.pdf
Softaken Excel to vCard Converter Software.pdf
PTS Company Brochure 2025 (1).pdf.......

Introduction to Zend Framework 2

  • 2. Hi! I’m John! • Involved in PHP since circa 1996 • Sr. Architect, Zend Global Services • PHP Core Contributor • ZF Contributor
  • 3. Introduction to ZF2  In this talk we’re going to look over the key components of any ZF2 application • The Model, View, and Controller architecture • The Module Architecture • Service Manager • Event Manager
  • 4. Getting Started  The easiest way to get started in ZF2 is to start with the skeleton application: https://github.com/zendframework/zendskeletonapplication $ composer create-project -sdev -repository-url=“https://packages.zendframework.com” zendframework/skeleton-application /path/to/install
  • 5. Basic ZF2 File structure  config/ - Application Config  module/ - Application modules  public/ - Docroot for images, css, etc.
  • 6. ZF2 Modules  In ZF2 modules are a core concept when developing applications. Everything including the application is a module.  Modules can be application-specific or can be written generically and then loaded into the application via composer
  • 7. How do Modules work?  Every ZF2 module starts with a Module class which describes the module and the things it provides to the application  Services  Event Handlers  Controllers  Routes  Etc.
  • 8. How do Modules work?  Modules also have their own configuration files which can setup default values that are later over-written by the application’s configurations.  Useful for creating module-specific routes, or module-specific configurations, etc.  config/module.config.php
  • 9. How do Modules work?  The module class can implement a number of useful methods  getAutoLoaderConfig() – configure the way classes are autoloaded through this module  getServiceConfig() – set up the way services this module provides can be created and accessed  getModuleDependencies() – Define module dependencies  onBootstrap() – Executed when module is fired up
  • 10. How are modules structured?
  • 11. ZF2 MVC  In ZF2, the MVC architecture is entirely driven by the events (ZendMvcMvcEvent)  Bootstrap  Dispatch  Dispatch Error  Finish  Render  Render Error  Route
  • 12. ZF2 MVC  Typically you don’t have to worry too much about these things, as the basic MVC takes care of things for you  You define routes in the application config which map to controllers / actions  These controller / actions get executed and return a result  This result is passed to the View component to be rendered
  • 13. ZF2 MVC  Events are useful however because they allow you to augment or short-circuit the default behavior  I.e. Catch the dispatch event and make sure the user is authenticated  I.e. Catch the dispatch error and render error events to do custom logging
  • 14. Service Manager  MVC, and ZF2 applications in general rely heavily on something called the Service Manager to deal with application dependencies  Examples: The DB adapter used by the application is created by the Service Manager
  • 15. Service Manager  Implementing dependencies and components as services allows modules to be completely decoupled from each other  Services are identified by unique ID, which is referenced when the service is required  Customization (i.e. a different DB adapter) can be done simply by over-writing the factory associated with that unique ID
  • 16. Service Manager  In a module services can be defined in various locations  module.config.php (the ‘service_manager’ key)  Module::getServiceConfig() (the programatic approach)
  • 17. Service Manager  How services can be defined  By factory – identify the key to either a class that implements a Factory interface or other callable which returns the instance  By invokable – Simply identify the class associated with this service  Aliases – Services can have an alias for complicated dependency scenarios
  • 18. Working with Routes  Routes are one of the first things done in MVC  Goal – Match a given URL to something actionable  Examples  Literal Route (i.e. /exactly/this)  Segment Route (i.e. /articles[/:article_id])  RegEx (i.e. /blog/(?<id>[a-zA-Z0-9_-]+)
  • 19. Working with Routes  Below is an example simple route
  • 20. Controllers  When a route is matched, a dispatch event is fired, and the corresponding controller/action is executed  The controller is loaded via service manager (allowing for dependency injection)  Controller action is called and one of two things can be returned  A Response object  An array or instance of the ViewModel class
  • 21. Summary  This is a very surface-level exploration into the complex possibilities of ZF2, but enough to get started.  Get to know Service Manager and Event Manager very well and they will serve you fantastically, allowing you to write powerful reusable components
  • 22. Any questions? Slides will be available at http://www.slideshare.net/coogle