18
July 18, 2014 Tarun Kumar Singhal Zend Framework 2

Zend Framework 2

Embed Size (px)

DESCRIPTION

Overview on Zend Framework 2. It include on Composer, Routing, custom configuration setup, session management, Bootstrap CSS usage etc..

Citation preview

Page 1: Zend Framework 2

July 18, 2014Tarun Kumar Singhal

Zend Framework 2

Page 2: 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

Page 3: Zend Framework 2

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

Page 4: Zend Framework 2

Directory Tree Structure

config/---autoload/---*.config.phpdatamodule---ModuleName------config------language------src---------ModuleName------------Controller------------Form------------Model------viewpublicvendor

• The top level of the module contains organisational directories along with the “Module.php” and “autoload_classmap.php” files.

• config - for configuration filessrc - for PHP classesview - for view scripts

Zend Framework 2

Page 5: Zend Framework 2

Application Code-Flow

Zend Framework 2

Page 6: Zend Framework 2

Zend Framework 2

Page 7: 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

Page 8: 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

Page 9: Zend Framework 2

RoutingRouting 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

Page 10: 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 Zend\Session\Container;

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');

Page 11: Zend Framework 2

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

Page 12: 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

Page 13: Zend Framework 2

Demo

BitBucket Help URL : https://bitbucket.org/dlu/dlutwbootstrap

Download the Twitter-Bootstrap module to use bootstrap CSSModule: dlu/DluTwBootstrap via zend studio

Zend Framework 2

Page 14: Zend Framework 2

Modules Custom Config file>> Create custom config file at module's config dir:

<?phpreturn 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

Page 15: Zend Framework 2

Service Manager

ServiceManager component is an implementation of the Service Locator pattern.

OR, we can sayA simple application registry that provides objects (in a lazy loaded fashion) within application as needed – but with some nice additions.

Zend Framework 2

Page 16: Zend Framework 2

Database Connectivity with one Database

Zend Framework 2

Page 17: Zend Framework 2

Database Connectivity with multiple Database

Zend Framework 2

Page 18: Zend Framework 2

Thank You

Zend Framework 2