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
3. 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
7. 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
8. 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
9. 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
10. 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');
11. 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
12. 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
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 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
15. 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