KEMBAR78
Get Started with Zend Framework 2 | PPTX
Get started with 
Zend Framework 2 
Presenter : 
Pravasini Sahoo, Mindfire Solutions 
Date: 12th August 2014
About Me 
“ Working as a PHP Developer in MFS for around 4years. I started my professional career at Mindfire on 2010. I 
had done some projects using Zend 1.12 version and some using Zend 2. My skill is on PHP, MySQL, CSS, CSS3, 
HTML5, JQuery, AJAX, JavaScript, XML, ZendFramework, GoogleAnalytics, HTML , FacebookAPI, YouTubeAPI, 
OCP1, Znedframework2, TwitterBootstrap, JSON “ 
Certifications 
• Zend Certified Engineer (ZCE) 
Zend PHP 5.3 Certification 
• Oracle Certified Professional 
OCP MySQL 5 Developer - Part 1 - 1Z0-871 
• Microsoft Certified Professional 
MCP – Programming in HTML5 with JavaScript and CSS3 – MCTS 70-480 
2 | 12 Aug 2014
Agenda 
1. Introduction to Framework 
2. What is MVC? 
3. Why to use Zend Framework 2? 
4. Zend2 Installation 
5. Control Flow 
6. Demo on a CRUD application 
3 | 12 Aug 2014
Introduction to Framework 
4 | 12 Aug 2014
1. Introduction to Framework 
“A Framework is a universal, reusable software platform to 
develop software applications, products and solutions. In other 
words, we can say it is some kind of library, a piece of software, 
which provide web developers with code base and consistent 
standardized ways of creating web applications”. 
5 | 12 Aug 2014
Benefits of using Framework 
1. Code and File Organization 
2. The MVC Pattern 
3. Enforcing of Good Coding Standards 
4. Utilities and Libraries 
5. Less Code & Faster Development 
6. Community Support 
7. Security 
8. Performance Tools 
9. Simplified and Pretty URLs 
10. Efficiently Access Database ... and lot more 
6 | 12 Aug 2014
What is MVC? 
7 | 12 Aug 2014
2. What is MVC? 
MVC is a software architecture - the structure of the system - that separates 
domain/application/business (whatever you prefer) logic from the rest of 
the user interface. It does this by separating the application into three parts: 
the model, the view, and the controller. 
The controller receives user input and makes calls to model objects and the 
view to perform appropriate actions. 
The model manages fundamental behaviors and data of the application. 
The view effectively provides the user interface element of the application. 
8 | 12 Aug 2014
An XYZ Company Hierarchy 
INFORMATION 
DESK 
DEPARTMENT ONE DEPARTMENT TWO 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
9 | 12 Aug 2014
Customer arrives…. 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
10 | 12 Aug 2014 
DEPARTMENT ONE DEPARTMENT TWO
Information desk greets him/her 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
11 | 12 Aug 2014
..gives him/her directions.. 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
12 | 12 Aug 2014
Warehouse folks do things 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
13 | 12 Aug 2014
Stuff is ready for delivery 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
14 | 12 Aug 2014
Customer is happy. 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
15 | 12 Aug 2014
16 | 12 Aug 2014
17 | 12 Aug 2014
http://framework.zend.com/ 
18 | 12 Aug 2014
Our Application 
VIEW VIEW 
CONTROLLER CONTROLLER 
MODEL 
19 | 12 Aug 2014
Back to the XYZ company… 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
20 | 12 Aug 2014
Why to use Framework 2? 
21 | 12 Aug 2014
We need to move a department.. 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
22 | 12 Aug 2014
Dependency problem 
INFORMATION 
DESK 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
23 | 12 Aug 2014
In our Application 
VIEW VIEW 
CONTROLLER CONTROLLER 
MODEL 
24 | 12 Aug 2014
Same problem 
VIEW VIEW 
CONTROLLER CONTROLLER 
MODEL 
25 | 12 Aug 2014
Solving company problem 
ACCOUNTS MANAGER ACCOUNTS MANAGER 
TECHNICAL OFFICE TECHNICAL OFFICE 
WAREHOUSE 
INFORMATION 
DESK 
WAREHOUSE 
26 | 12 Aug 2014
Same with our application 
VIEW VIEW 
CONTROLLER CONTROLLER 
MODEL MODEL 
27 | 12 Aug 2014
Project delivered ! 
VIEW 
CONTROLLER 
VIEW 
CONTROLLER 
MODEL 
MODEL 
28 | 12 Aug 2014
Let’s start a new one… 
VIEW 
CONTROLLER 
VIEW 
CONTROLLER 
MODEL 
MODEL 
29 | 12 Aug 2014
Hey ! We need this thing 
VIEW 
CONTROLLER 
VIEW 
CONTROLLER 
MODEL 
MODEL 
30 | 12 Aug 2014
Problem Solved ! 
VIEW 
CONTROLLER 
VIEW 
CONTROLLER 
MODEL 
MODEL VIEW 
CONTROLLER 
MODEL 
31 | 12 Aug 2014
http://framework.zend.com/ 
32 | 12 Aug 2014
Namespace + Module.php = Module 
33 | 12 Aug 2014
Namespace + Module.php = Module 
Namespace Album; 
Class Module { } 
34 | 12 Aug 2014
What’s in a Module ? 
Feature 
35 | 12 Aug 2014
What’s in a Module ? 
Feature 
Routing 
Controller 
View 
PHP Classes 
Configuration 
. . . 
36 | 12 Aug 2014
Business Logic Hints 
Feature 
Routing 
Controller 
View 
PHP Classes 
Configuration 
. . . 
Services 
Helpers/ Plugins 
Mappers 
. . . 
37 | 12 Aug 2014
Zend2 Installation 
38 | 12 Aug 2014
Cloning 
git clone 
https://github.com/zendframework/ZendSkeletonApplication 
39 | 12 Aug 2014
Composer.json 
{ 
"name": "zendframework/skeleton-application", 
"description": "Skeleton Application for ZF2", 
"license": "BSD-3-Clause", 
"keywords": [ 
"framework", 
"zf2" 
], 
"homepage": "http://framework.zend.com/", 
"require": { 
"php": ">=5.3.3", 
"zendframework/zendframework": "2.3.*" 
} 
} 
40 | 12 Aug 2014
Composer.json 
{ 
"name": "zendframework/skeleton-application", 
"description": "Skeleton Application for ZF2", 
"license": "BSD-3-Clause", 
"keywords": [ 
"framework", 
"zf2" 
], 
"homepage": "http://framework.zend.com/", 
"require": { 
"php": ">=5.3.3", 
"zendframework/zendframework": "2.3.*" 
} 
} 
41 | 12 Aug 2014
Installation 
cd ZendSkeletonApplication 
php composer.phar self-update 
php composer.phar install 
42 | 12 Aug 2014
Installation 
cd ZendSkeletonApplication 
php composer.phar self-update 
> Installing zendframework/zendframework 
43 | 12 Aug 2014
File System Layout 
44 | 12 Aug 2014
File System Layout 
Application wide configuration 
45 | 12 Aug 2014
File System Layout 
document, cached file, coding 
standard and guidelines 
46 | 12 Aug 2014
File System Layout 
Public Document Root 
47 | 12 Aug 2014
File System Layout 
Our Modules 
48 | 12 Aug 2014
File System Layout 
} Third Party Modules 
49 | 12 Aug 2014
Focusing on a module… 
Module specific configuration 
50 | 12 Aug 2014
What’s inside a module ? 
Module PHP Source Files 
(Controller, Form, Model, Services …) 
51 | 12 Aug 2014
What’s inside a module ? 
Module test files 
52 | 12 Aug 2014
What’s inside a module ? 
View Stuff 
(view files, layouts, partials) 
53 | 12 Aug 2014
Control Flow 
54 | 12 Aug 2014
index.php 
<?php 
/** 
* This makes our life easier when dealing with paths. Everything is relative 
* to the application root now. 
*/ 
chdir(dirname(__DIR__)); 
// Decline static file requests back to the PHP built-in webserver 
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . 
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { 
return false; 
} 
// Setup autoloading 
require 'init_autoloader.php'; 
// Run the application! 
ZendMvcApplication::init(require 'config/application.config.php')->run(); 
55 | 12 Aug 2014
index.php 
<?php 
/** 
* This makes our life easier when dealing with paths. Everything is relative 
* to the application root now. 
*/ 
chdir(dirname(__DIR__)); 
// Decline static file requests back to the PHP built-in webserver 
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . 
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { 
return false; 
} 
// Setup autoloading 
require 'init_autoloader.php'; 
// Run the application! 
ZendMvcApplication::init(require 'config/application.config.php')->run(); 
56 | 12 Aug 2014
Config/application.config.php 
<?php 
return array( 
// This should be an array of module namespaces used in the application. 
'modules' => array( 
'Application', 
'Album' 
), 
// These are various options for the listeners attached to the ModuleManager 
'module_listener_options' => array( 
'module_paths' => array( 
'./module', 
'./vendor', 
), 
'config_glob_paths' => array( 
'config/autoload/{,*.}{global,local}.php', 
) 
) 
); 
57 | 12 Aug 2014
Module.php 
namespace Application; 
use ZendMvcModuleRouteListener; 
use ZendMvcMvcEvent; 
class Module 
{ 
public function onBootstrap(MvcEvent $e) 
{ ... } 
public function getConfig() { 
return include __DIR__ . '/config/module.config.php'; 
} 
public function getAutoloaderConfig() 
{ ... } 
} 
58 | 12 Aug 2014
Module configuration file 
// config/module.config.php 
return array( 
'router' => array( 
'routes' => array(...) 
), 
'controllers' => array(...), 
'service_manager' => array(...), 
'view_manager' => array(...), 
... 
) 
59 | 12 Aug 2014
Controllers 
namespace ApplicationController; 
use ZendMvcControllerAbstractActionController; 
use ZendViewModelViewModel; 
class IndexController extends AbstractActionController 
{ 
public function indexAction() 
{ 
return new ViewModel(); 
} 
} 
60 | 12 Aug 2014
Actions 
namespace ApplicationController; 
use ZendMvcControllerAbstractActionController; 
use ZendViewModelViewModel; 
class IndexController extends AbstractActionController 
{ 
public function indexAction() 
{ 
return new ViewModel(); 
} 
} 
61 | 12 Aug 2014
Feature A 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
62 | 12 Aug 2014
Feature A 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Feature B 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Feature C 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
63 | 12 Aug 2014
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Modules are merged at runtime 
64 | 12 Aug 2014
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Routing 
Controller 
Views 
PHP Classes 
. . . 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Modules are merged at runtime 
Configurations 
65 | 12 Aug 2014
We can override things… 
Views / Layouts 
Routing Rules 
All Other Configuration Parameters 
66 | 12 Aug 2014
We can override things 
Views / Layouts 
Routing Rules } 
All Other Configuration Parameters 
Do NOT modify 
original 3rd party 
modules! 
67 | 12 Aug 2014
Custom configuration 
} Do not modify anything from here ! 
68 | 12 Aug 2014
Modules are merged at runtime 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
Routing 
Controller 
Views 
PHP Classes 
Configurations 
. . . 
69 | 12 Aug 2014
This happens for all modules 
config/application.config.php 
return array( 
'modules' => array( 
'DoctrineModule', 
'DoctrineORMModule', 
'Application', 
), 
), 
... 
70 | 12 Aug 2014 
} Order is important
Demo on a CRUD application 
71 | 12 Aug 2014
References 
1. http://framework.zend.com/manual/2.0/en/ref/overview.html 
2. http://framework.zend.com/manual/2.0/en/user-guide/modules.html 
3. http://framework.zend.com/about/faq/ 
4. http://www.slideshare.net/maraspin/zf2-modular-architecture-taking-advantage- 
of-it 
5. http://blog.hock.in/2012/09/06/zf2-for-zf1-users-part-1/ 
6. http://stackoverflow.com/questions/12314300/zend-framework-1-vs-zend-framework- 
2-performance 
72 | 12 Aug 2014
73 | 12 Aug 2014 
Q & A
Thank You ! 
74 | 12 Aug 2014

Get Started with Zend Framework 2

  • 1.
    Get started with Zend Framework 2 Presenter : Pravasini Sahoo, Mindfire Solutions Date: 12th August 2014
  • 2.
    About Me “Working as a PHP Developer in MFS for around 4years. I started my professional career at Mindfire on 2010. I had done some projects using Zend 1.12 version and some using Zend 2. My skill is on PHP, MySQL, CSS, CSS3, HTML5, JQuery, AJAX, JavaScript, XML, ZendFramework, GoogleAnalytics, HTML , FacebookAPI, YouTubeAPI, OCP1, Znedframework2, TwitterBootstrap, JSON “ Certifications • Zend Certified Engineer (ZCE) Zend PHP 5.3 Certification • Oracle Certified Professional OCP MySQL 5 Developer - Part 1 - 1Z0-871 • Microsoft Certified Professional MCP – Programming in HTML5 with JavaScript and CSS3 – MCTS 70-480 2 | 12 Aug 2014
  • 3.
    Agenda 1. Introductionto Framework 2. What is MVC? 3. Why to use Zend Framework 2? 4. Zend2 Installation 5. Control Flow 6. Demo on a CRUD application 3 | 12 Aug 2014
  • 4.
    Introduction to Framework 4 | 12 Aug 2014
  • 5.
    1. Introduction toFramework “A Framework is a universal, reusable software platform to develop software applications, products and solutions. In other words, we can say it is some kind of library, a piece of software, which provide web developers with code base and consistent standardized ways of creating web applications”. 5 | 12 Aug 2014
  • 6.
    Benefits of usingFramework 1. Code and File Organization 2. The MVC Pattern 3. Enforcing of Good Coding Standards 4. Utilities and Libraries 5. Less Code & Faster Development 6. Community Support 7. Security 8. Performance Tools 9. Simplified and Pretty URLs 10. Efficiently Access Database ... and lot more 6 | 12 Aug 2014
  • 7.
    What is MVC? 7 | 12 Aug 2014
  • 8.
    2. What isMVC? MVC is a software architecture - the structure of the system - that separates domain/application/business (whatever you prefer) logic from the rest of the user interface. It does this by separating the application into three parts: the model, the view, and the controller. The controller receives user input and makes calls to model objects and the view to perform appropriate actions. The model manages fundamental behaviors and data of the application. The view effectively provides the user interface element of the application. 8 | 12 Aug 2014
  • 9.
    An XYZ CompanyHierarchy INFORMATION DESK DEPARTMENT ONE DEPARTMENT TWO ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 9 | 12 Aug 2014
  • 10.
    Customer arrives…. INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 10 | 12 Aug 2014 DEPARTMENT ONE DEPARTMENT TWO
  • 11.
    Information desk greetshim/her INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 11 | 12 Aug 2014
  • 12.
    ..gives him/her directions.. INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 12 | 12 Aug 2014
  • 13.
    Warehouse folks dothings INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 13 | 12 Aug 2014
  • 14.
    Stuff is readyfor delivery INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 14 | 12 Aug 2014
  • 15.
    Customer is happy. INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 15 | 12 Aug 2014
  • 16.
    16 | 12Aug 2014
  • 17.
    17 | 12Aug 2014
  • 18.
  • 19.
    Our Application VIEWVIEW CONTROLLER CONTROLLER MODEL 19 | 12 Aug 2014
  • 20.
    Back to theXYZ company… INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 20 | 12 Aug 2014
  • 21.
    Why to useFramework 2? 21 | 12 Aug 2014
  • 22.
    We need tomove a department.. INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 22 | 12 Aug 2014
  • 23.
    Dependency problem INFORMATION DESK ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE 23 | 12 Aug 2014
  • 24.
    In our Application VIEW VIEW CONTROLLER CONTROLLER MODEL 24 | 12 Aug 2014
  • 25.
    Same problem VIEWVIEW CONTROLLER CONTROLLER MODEL 25 | 12 Aug 2014
  • 26.
    Solving company problem ACCOUNTS MANAGER ACCOUNTS MANAGER TECHNICAL OFFICE TECHNICAL OFFICE WAREHOUSE INFORMATION DESK WAREHOUSE 26 | 12 Aug 2014
  • 27.
    Same with ourapplication VIEW VIEW CONTROLLER CONTROLLER MODEL MODEL 27 | 12 Aug 2014
  • 28.
    Project delivered ! VIEW CONTROLLER VIEW CONTROLLER MODEL MODEL 28 | 12 Aug 2014
  • 29.
    Let’s start anew one… VIEW CONTROLLER VIEW CONTROLLER MODEL MODEL 29 | 12 Aug 2014
  • 30.
    Hey ! Weneed this thing VIEW CONTROLLER VIEW CONTROLLER MODEL MODEL 30 | 12 Aug 2014
  • 31.
    Problem Solved ! VIEW CONTROLLER VIEW CONTROLLER MODEL MODEL VIEW CONTROLLER MODEL 31 | 12 Aug 2014
  • 32.
  • 33.
    Namespace + Module.php= Module 33 | 12 Aug 2014
  • 34.
    Namespace + Module.php= Module Namespace Album; Class Module { } 34 | 12 Aug 2014
  • 35.
    What’s in aModule ? Feature 35 | 12 Aug 2014
  • 36.
    What’s in aModule ? Feature Routing Controller View PHP Classes Configuration . . . 36 | 12 Aug 2014
  • 37.
    Business Logic Hints Feature Routing Controller View PHP Classes Configuration . . . Services Helpers/ Plugins Mappers . . . 37 | 12 Aug 2014
  • 38.
    Zend2 Installation 38| 12 Aug 2014
  • 39.
    Cloning git clone https://github.com/zendframework/ZendSkeletonApplication 39 | 12 Aug 2014
  • 40.
    Composer.json { "name":"zendframework/skeleton-application", "description": "Skeleton Application for ZF2", "license": "BSD-3-Clause", "keywords": [ "framework", "zf2" ], "homepage": "http://framework.zend.com/", "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.3.*" } } 40 | 12 Aug 2014
  • 41.
    Composer.json { "name":"zendframework/skeleton-application", "description": "Skeleton Application for ZF2", "license": "BSD-3-Clause", "keywords": [ "framework", "zf2" ], "homepage": "http://framework.zend.com/", "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.3.*" } } 41 | 12 Aug 2014
  • 42.
    Installation cd ZendSkeletonApplication php composer.phar self-update php composer.phar install 42 | 12 Aug 2014
  • 43.
    Installation cd ZendSkeletonApplication php composer.phar self-update > Installing zendframework/zendframework 43 | 12 Aug 2014
  • 44.
    File System Layout 44 | 12 Aug 2014
  • 45.
    File System Layout Application wide configuration 45 | 12 Aug 2014
  • 46.
    File System Layout document, cached file, coding standard and guidelines 46 | 12 Aug 2014
  • 47.
    File System Layout Public Document Root 47 | 12 Aug 2014
  • 48.
    File System Layout Our Modules 48 | 12 Aug 2014
  • 49.
    File System Layout } Third Party Modules 49 | 12 Aug 2014
  • 50.
    Focusing on amodule… Module specific configuration 50 | 12 Aug 2014
  • 51.
    What’s inside amodule ? Module PHP Source Files (Controller, Form, Model, Services …) 51 | 12 Aug 2014
  • 52.
    What’s inside amodule ? Module test files 52 | 12 Aug 2014
  • 53.
    What’s inside amodule ? View Stuff (view files, layouts, partials) 53 | 12 Aug 2014
  • 54.
    Control Flow 54| 12 Aug 2014
  • 55.
    index.php <?php /** * This makes our life easier when dealing with paths. Everything is relative * to the application root now. */ chdir(dirname(__DIR__)); // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } // Setup autoloading require 'init_autoloader.php'; // Run the application! ZendMvcApplication::init(require 'config/application.config.php')->run(); 55 | 12 Aug 2014
  • 56.
    index.php <?php /** * This makes our life easier when dealing with paths. Everything is relative * to the application root now. */ chdir(dirname(__DIR__)); // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } // Setup autoloading require 'init_autoloader.php'; // Run the application! ZendMvcApplication::init(require 'config/application.config.php')->run(); 56 | 12 Aug 2014
  • 57.
    Config/application.config.php <?php returnarray( // This should be an array of module namespaces used in the application. 'modules' => array( 'Application', 'Album' ), // These are various options for the listeners attached to the ModuleManager 'module_listener_options' => array( 'module_paths' => array( './module', './vendor', ), 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ) ) ); 57 | 12 Aug 2014
  • 58.
    Module.php namespace Application; use ZendMvcModuleRouteListener; use ZendMvcMvcEvent; class Module { public function onBootstrap(MvcEvent $e) { ... } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getAutoloaderConfig() { ... } } 58 | 12 Aug 2014
  • 59.
    Module configuration file // config/module.config.php return array( 'router' => array( 'routes' => array(...) ), 'controllers' => array(...), 'service_manager' => array(...), 'view_manager' => array(...), ... ) 59 | 12 Aug 2014
  • 60.
    Controllers namespace ApplicationController; use ZendMvcControllerAbstractActionController; use ZendViewModelViewModel; class IndexController extends AbstractActionController { public function indexAction() { return new ViewModel(); } } 60 | 12 Aug 2014
  • 61.
    Actions namespace ApplicationController; use ZendMvcControllerAbstractActionController; use ZendViewModelViewModel; class IndexController extends AbstractActionController { public function indexAction() { return new ViewModel(); } } 61 | 12 Aug 2014
  • 62.
    Feature A Routing Controller Views PHP Classes Configurations . . . 62 | 12 Aug 2014
  • 63.
    Feature A Routing Controller Views PHP Classes Configurations . . . Feature B Routing Controller Views PHP Classes Configurations . . . Feature C Routing Controller Views PHP Classes Configurations . . . 63 | 12 Aug 2014
  • 64.
    Routing Controller Views PHP Classes Configurations . . . Routing Controller Views PHP Classes Configurations . . . Routing Controller Views PHP Classes Configurations . . . Modules are merged at runtime 64 | 12 Aug 2014
  • 65.
    Routing Controller Views PHP Classes Configurations . . . Routing Controller Views PHP Classes . . . Routing Controller Views PHP Classes Configurations . . . Modules are merged at runtime Configurations 65 | 12 Aug 2014
  • 66.
    We can overridethings… Views / Layouts Routing Rules All Other Configuration Parameters 66 | 12 Aug 2014
  • 67.
    We can overridethings Views / Layouts Routing Rules } All Other Configuration Parameters Do NOT modify original 3rd party modules! 67 | 12 Aug 2014
  • 68.
    Custom configuration }Do not modify anything from here ! 68 | 12 Aug 2014
  • 69.
    Modules are mergedat runtime Routing Controller Views PHP Classes Configurations . . . Routing Controller Views PHP Classes Configurations . . . Routing Controller Views PHP Classes Configurations . . . 69 | 12 Aug 2014
  • 70.
    This happens forall modules config/application.config.php return array( 'modules' => array( 'DoctrineModule', 'DoctrineORMModule', 'Application', ), ), ... 70 | 12 Aug 2014 } Order is important
  • 71.
    Demo on aCRUD application 71 | 12 Aug 2014
  • 72.
    References 1. http://framework.zend.com/manual/2.0/en/ref/overview.html 2. http://framework.zend.com/manual/2.0/en/user-guide/modules.html 3. http://framework.zend.com/about/faq/ 4. http://www.slideshare.net/maraspin/zf2-modular-architecture-taking-advantage- of-it 5. http://blog.hock.in/2012/09/06/zf2-for-zf1-users-part-1/ 6. http://stackoverflow.com/questions/12314300/zend-framework-1-vs-zend-framework- 2-performance 72 | 12 Aug 2014
  • 73.
    73 | 12Aug 2014 Q & A
  • 74.
    Thank You ! 74 | 12 Aug 2014