+ All Categories
Home > Technology > Zend Framework

Zend Framework

Date post: 11-May-2015
Category:
Upload: opensource-technologies-pvt-ltd
View: 12,643 times
Download: 9 times
Share this document with a friend
Description:
What is Zend Framework? Getting and Installing Zend Framework MVC overview Quick Start to developing applications using Zend Framework's
Popular Tags:
37
Zend Framework
Transcript
Page 1: Zend Framework

Zend Framework

Page 2: Zend Framework

• What is Zend Framework?

• Getting and Installing Zend Framework

• MVC overview

• Quick Start to developing applications using Zend Framework's

Page 3: Zend Framework

• PHP 5 library for web development productivity

• Free, Open source

• Class library – fully OOP

• Documentation – in many languages

• Quality & testing – fully unit tested

What is Zend Framework?

Page 4: Zend Framework

What's in Zend Framework?

Page 5: Zend Framework

• PHP 5.1.4

• Web server

• Standard installation

• Commonly no additional extensions needed

Requirments

Page 6: Zend Framework

The

directory

tree

quickstart|-- application| |-- Bootstrap.php| |-- configs| | `-- application.ini| |-- controllers| | |-- ErrorController.php| | `-- IndexController.php| |-- models| `-- views| |-- helpers| `-- scripts| |-- error| | `-- error.phtml| `-- index| `-- index.phtml|-- library|-- public| `-- index.php`-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml

14 directories, 10 files

quickstart|-- application| |-- Bootstrap.php| |-- configs| | `-- application.ini| |-- controllers| | |-- ErrorController.php| | `-- IndexController.php| |-- models| `-- views| |-- helpers| `-- scripts| |-- error| | `-- error.phtml| `-- index| `-- index.phtml|-- library|-- public| `-- index.php`-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml

14 directories, 10 files

Page 7: Zend Framework

Sample INI config

[production]app.name = "Foo!"db.adapter = "Pdo_Mysql"db.params.username = "foo"db.params.password = "bar"db.params.dbname = "foodb"db.params.host = "127.0.0.1"

[testing : production]db.adapter = "Pdo_Sqlite"db.params.dbname = APPLICATION_PATH "/data/test.db"

[production]app.name = "Foo!"db.adapter = "Pdo_Mysql"db.params.username = "foo"db.params.password = "bar"db.params.dbname = "foodb"db.params.host = "127.0.0.1"

[testing : production]db.adapter = "Pdo_Sqlite"db.params.dbname = APPLICATION_PATH "/data/test.db"

Page 8: Zend Framework

Getting and Installing

Zend Framework

Page 9: Zend Framework

Always found at:http://framework.zend.com

/download/latest

Page 10: Zend Framework

• Use CLI:% tar xzf ZendFramework-1.9.2-minimal.tar.gz% unzip ZendFramework-1.9.2-minimal.zip

• Or use a GUI file manager

Unzip/Untar

Page 11: Zend Framework

Add to your

include_path

<?phpset_include_path(implode(PATH_SEPARATOR, array( '.', '/home/matthew/zf/library', get_include_path(),)));

<?phpset_include_path(implode(PATH_SEPARATOR, array( '.', '/home/matthew/zf/library', get_include_path(),)));

Page 12: Zend Framework

Step 1:Create the project

Page 13: Zend Framework

Using the Model in the ControllerUsing the Model in the ControllerLocate the zf utility

In bin/zf.sh of bin/zf.bat of your ZF install (choose based on your OS)

Place bin/ in your path, or create an alias on your path:

alias zf=/path/to/bin/zf.sh

Page 14: Zend Framework

Create the project

# Unix:% zf.sh create project quickstart

# DOS/Windows:C:> zf.bat create project quickstart

# Unix:% zf.sh create project quickstart

# DOS/Windows:C:> zf.bat create project quickstart

Page 15: Zend Framework

Create a vhost

<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /abs/path/to/quickstart/public ServerName quickstart

<Directory /abs/path/to/quickstart/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>

<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /abs/path/to/quickstart/public ServerName quickstart

<Directory /abs/path/to/quickstart/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>

Page 16: Zend Framework

Fire up your browser!

Page 17: Zend Framework

Configuration[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1

[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1

[production]phpSettings.display_startup_errors = 0phpSettings.display_errors = 0includePaths.library = APPLICATION_PATH "/../library"bootstrap.path = APPLICATION_PATH "/Bootstrap.php"bootstrap.class = "Bootstrap"resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"

[staging : production]

[testing : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1

[development : production]phpSettings.display_startup_errors = 1phpSettings.display_errors = 1

Page 18: Zend Framework

.htaccess file

SetEnv APPLICATION_ENV development

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]

SetEnv APPLICATION_ENV development

RewriteEngine OnRewriteCond %{REQUEST_FILENAME} -s [OR]RewriteCond %{REQUEST_FILENAME} -l [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^.*$ - [NC,L]RewriteRule ^.*$ index.php [NC,L]

Page 19: Zend Framework

Step 2:Create a controller

Page 20: Zend Framework

All controllers extend Zend_Controller_Action

Naming conventions

Controllers end with 'Controller': IndexController, GuestbookController

Action methods end with 'Action':signAction(), displayAction(), listAction()

Controllers should be in the application/controllers/ directory, and named after the class, with a “.php” suffix:

application/controllers/IndexController.phpapplication/controllers/GuestbookController.php

Create a controller

Page 21: Zend Framework

IndexController.php

Page 22: Zend Framework

Step 3:Create the model

Page 23: Zend Framework

Using the Model in the ControllerUsing the Model in the ControllerUsing the Model in the Controller

• Controller needs to retrieve Model

• To start, let's fetch listings

Page 24: Zend Framework

Using the Model in the ControllerUsing the Model in the ControllerAdding the Model to the Controller

Page 25: Zend Framework

Using the Model in the ControllerUsing the Model in the ControllerTable Module – Access Methods

Page 26: Zend Framework

Step 4:Create views

Page 27: Zend Framework

Create a view scriptCreate a view

• View scripts go in application/views/scripts/

• View script resolution looks for a view script in a subdirectory named after the controller

– Controller name used is same as it appears on the url:• “GuestbookController” appears on the URL as

“guestbook”

• View script name is the action name as it appears on the url:

• “signAction()” appears on the URL as “sign”

Page 28: Zend Framework

index/index.phtml view script

Page 29: Zend Framework

Step 5:Create a form

Page 30: Zend Framework

Create a Form

Zend_Form:

• Flexible form generations

• Element validation and filtering

• Rendering

View helper to render element

Decorators for labels and HTML wrappers

• Optional Zend_Config configuraion

Page 31: Zend Framework

Create a form – Identify elements

Guestbook form:

• Email address

• Comment

• Captcha to reduce spam entries

• Submit button

Page 32: Zend Framework

Create a form – Guestbook form

Page 33: Zend Framework

Using the Form in the Controller

• Controller needs to fetch form object

• On landing page, display the form

• On POST requests, attempt to validate the form

• On successful submission, redirect

Page 34: Zend Framework

Adding the form to the controllerAdding the form to the controller

Page 35: Zend Framework

Step 6:Create a layout

Page 36: Zend Framework

Layouts

• We want our application views to appear in this:

Page 37: Zend Framework

Thank you.


Recommended