July 18, 2014
Tarun Kumar Singhal
Zend Framework 2
Zend Framework 2
Discussion Points
About
Directory Tree Structure
Skeleton Application
Composer
Routing
Session Management
CSS Styleshet and Twitter Bootstrap
Module Custom Config file
Service Manager
Database Connectivity with one or more
About

Zend Framework 2 is an open source framework for
developing web applications and services using
PHP 5.3+.

Zend Framework 2 uses 100% object-oriented code
and utilises most of the new features of PHP 5.3,
namely namespaces, late static binding, lambda
functions and closures.
Zend Framework 2
Directory Tree Structure
config/
---autoload/
---*.config.php
data
module
---ModuleName
------config
------language
------src
---------ModuleName
------------Controller
------------Form
------------Model
------view
public
vendor
• The top level of the module
contains organisational directories
along with the “Module.php” and
“autoload_classmap.php” files.
• config - for configuration files
src - for PHP classes
view - for view scripts
Zend Framework 2
Application Code-Flow
Zend Framework 2
Zend Framework 2
Skeleton Application
With the help of composer
# curl -sS https://getcomposer.org/installer | php // to get the composer.phar file
# php composer.phar create-project -sdev --repository-
url="https://packages.zendframework.com" zendframework/skeleton-application
path/to/install
# php composer.phar update
With the help of GIT
# Go to https://github.com/zendframework/ZendSkeletonApplication
Then click the “Zip” button. This will download the file with a name like
ZendSkeletonApplication-master.zip or similar.
Zend Framework 2
Composer
Composer is a tool for dependency management in PHP.
It deals with "packages" or libraries, but it manages them on a per-project
basis, installing them in a directory (e.g. vendor) inside your project.
The problem that Composer solves is this:
You have a project that depends on a number of libraries.
Some of those libraries depend on other libraries.
You declare the things you depend on.
Composer finds out which versions of which packages need to be
installed, and installs them
Zend Framework 2
Routing
Routing is the act of matching a request
to a given controller.
Routes are stored in the
“module.config.php” file found in the
config directory. In this file you can
modify existing routes and add new
routes.
Zend Framework 2
Session Management
Zend Framework 2
The session manager is a class that is responsible for all aspects of session management.
It initializes and configures configuration, storage and save handling.
Usage:
In module Controller class:
Use ZendSessionContainer;
In Action:
$session = new Container('User');
//to set session
$session->offsetSet('UserName', 'Demo User');
//get session
$session->offsetGet('UserName');
//session exist check
$session->offsetExists('UserName');
//destory session
$session->offsetUnset('UserName');
CSS Stylesheets and Twitter
Bootstrap
This is provided by default in ZF2 framework skeleton application.
Bootstrap has became a popular CSS framework, allowing to make your
web site professionally looking and visually appealing, even if you don’t
have advanced designer skills and without the need of creating basic
CSS rules (but, of course you can define your own custom CSS rules on
top of Bootstrap to customise your site’s appearance). Bootstrap is
freely distributed under the Apache License v.2.0.
Zend Framework 2
Cont...
Generally, the Bootstrap does the following things:
• It provides the CSS reset that is a style sheet defining styles for all
possible HTML elements. This ensures your web site will look the same
way in all web browsers.
• It provides the base CSS rules that define style of typography
(headings and text), tables, forms, buttons, images and so on.
• It defines the grid system. The grid system allows to arrange elements
on your web page in a grid-like structure.
• It defines useful web interface components like dropdown menus,
navigation bars, breadcrumbs, pagination and so on.
• It includes the JavaScript extensions that allow to make Bootstrap-
provided interface components more interactive. For example,
JavaScript is used to animate dropdown menus and display “modal
dialogs”.
Zend Framework 2
Demo
BitBucket Help URL : https://bitbucket.org/dlu/dlutwbootstrap
Download the Twitter-Bootstrap module to use bootstrap CSS
Module: dlu/DluTwBootstrap via zend studio
Zend Framework 2
Modules Custom Config file
>> Create custom config file at module's config
dir:
<?php
return array(
'report' => array(
'name' => 'Name'
),
);?>
>> In Controller's action of Module:
<?php
$config = $this->getServiceLocator ()->get
( 'config' );
$data = $config['report'];
>> Update method of config in module's
Module.php to merge the config array
Zend Framework 2
Service Manager
ServiceManager component is an implementation of the Service
Locator pattern.
OR, we can say
A simple application registry that provides objects (in a lazy
loaded fashion) within application as needed – but with some nice
additions.
Zend Framework 2
Database Connectivity with one
Database
Zend Framework 2
Database Connectivity with
multiple Database
Zend Framework 2
Thank You
Zend Framework 2

Zend Framework 2

  • 1.
    July 18, 2014 TarunKumar Singhal Zend Framework 2
  • 2.
    Zend Framework 2 DiscussionPoints About Directory Tree Structure Skeleton Application Composer Routing Session Management CSS Styleshet and Twitter Bootstrap Module Custom Config file Service Manager Database Connectivity with one or more
  • 3.
    About  Zend Framework 2is an open source framework for developing web applications and services using PHP 5.3+.  Zend Framework 2 uses 100% object-oriented code and utilises most of the new features of PHP 5.3, namely namespaces, late static binding, lambda functions and closures. Zend Framework 2
  • 4.
    Directory Tree Structure config/ ---autoload/ ---*.config.php data module ---ModuleName ------config ------language ------src ---------ModuleName ------------Controller ------------Form ------------Model ------view public vendor •The top level of the module contains organisational directories along with the “Module.php” and “autoload_classmap.php” files. • config - for configuration files src - for PHP classes view - for view scripts Zend Framework 2
  • 5.
  • 6.
  • 7.
    Skeleton Application With thehelp of composer # curl -sS https://getcomposer.org/installer | php // to get the composer.phar file # php composer.phar create-project -sdev --repository- url="https://packages.zendframework.com" zendframework/skeleton-application path/to/install # php composer.phar update With the help of GIT # Go to https://github.com/zendframework/ZendSkeletonApplication Then click the “Zip” button. This will download the file with a name like ZendSkeletonApplication-master.zip or similar. Zend Framework 2
  • 8.
    Composer Composer is atool for dependency management in PHP. It deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. The problem that Composer solves is this: You have a project that depends on a number of libraries. Some of those libraries depend on other libraries. You declare the things you depend on. Composer finds out which versions of which packages need to be installed, and installs them Zend Framework 2
  • 9.
    Routing Routing is theact of matching a request to a given controller. Routes are stored in the “module.config.php” file found in the config directory. In this file you can modify existing routes and add new routes. Zend Framework 2
  • 10.
    Session Management Zend Framework2 The session manager is a class that is responsible for all aspects of session management. It initializes and configures configuration, storage and save handling. Usage: In module Controller class: Use ZendSessionContainer; In Action: $session = new Container('User'); //to set session $session->offsetSet('UserName', 'Demo User'); //get session $session->offsetGet('UserName'); //session exist check $session->offsetExists('UserName'); //destory session $session->offsetUnset('UserName');
  • 11.
    CSS Stylesheets andTwitter Bootstrap This is provided by default in ZF2 framework skeleton application. Bootstrap has became a popular CSS framework, allowing to make your web site professionally looking and visually appealing, even if you don’t have advanced designer skills and without the need of creating basic CSS rules (but, of course you can define your own custom CSS rules on top of Bootstrap to customise your site’s appearance). Bootstrap is freely distributed under the Apache License v.2.0. Zend Framework 2
  • 12.
    Cont... Generally, the Bootstrapdoes the following things: • It provides the CSS reset that is a style sheet defining styles for all possible HTML elements. This ensures your web site will look the same way in all web browsers. • It provides the base CSS rules that define style of typography (headings and text), tables, forms, buttons, images and so on. • It defines the grid system. The grid system allows to arrange elements on your web page in a grid-like structure. • It defines useful web interface components like dropdown menus, navigation bars, breadcrumbs, pagination and so on. • It includes the JavaScript extensions that allow to make Bootstrap- provided interface components more interactive. For example, JavaScript is used to animate dropdown menus and display “modal dialogs”. Zend Framework 2
  • 13.
    Demo BitBucket Help URL: https://bitbucket.org/dlu/dlutwbootstrap Download the Twitter-Bootstrap module to use bootstrap CSS Module: dlu/DluTwBootstrap via zend studio Zend Framework 2
  • 14.
    Modules Custom Configfile >> Create custom config file at module's config dir: <?php return array( 'report' => array( 'name' => 'Name' ), );?> >> In Controller's action of Module: <?php $config = $this->getServiceLocator ()->get ( 'config' ); $data = $config['report']; >> Update method of config in module's Module.php to merge the config array Zend Framework 2
  • 15.
    Service Manager ServiceManager componentis an implementation of the Service Locator pattern. OR, we can say A simple application registry that provides objects (in a lazy loaded fashion) within application as needed – but with some nice additions. Zend Framework 2
  • 16.
    Database Connectivity withone Database Zend Framework 2
  • 17.
    Database Connectivity with multipleDatabase Zend Framework 2
  • 18.