SlideShare a Scribd company logo
19/10/09 Building Web Applications with Zend Framework 1
Building Web Applications with
Zend Framework
What is Zend Framework?
● A library of useful tools and classes?
● An MVC application framework?
● BOTH
Zend Framework Library
● Yes, it's a little like PEAR
● Huge active community
● High quality code
● Object Oriented PHP5
● Extensively tested
Zend Framework Library
● Advanced, loosely coupled toolset covering a
vast range of utilities, for example
Database Abstraction Table data gateway pattern Cache
Google Data API Adobe AMF Server HTTP Client
LDAP Email OpenID
PDF REST Client & Server Lucene Search
SOAP Internationalisation XMLRPC
Zend Application Framework
● MVC Design Pattern
● Rapid application development using
Zend_Tool command line utility
● Convention over configuration defaults to a
somewhat verbose directory structure however
flexibility allows developers choice
● Features include SEF URLS, custom routes,
context switching and a strong plugin
architecture
Zend Application Framework
● Helper objects are one of the highlights of the
application framework
● Controller Action Helpers for various controller tasks
– URL generation and redirection
– Context Switching
– Flash (single use) messaging
● View Helpers for visual / output encapsulation
– HTML generation
– Pagination
– Navigation
MVC Dispatch Overview
Request
Front Controller
Controller
Plugins
ControllerModels
Controller
Action Helpers
View
View Helpers
Layout
Response
Zend_Tool
● Zend_Tool can be used to
● Create projects
● Add modules, controllers, actions and views using
the default ZF directory structure
● Show information about projects and the PHP
environment
Some Examples
C:UsersPhilworkspace>zf create project phpmelb
Creating project at C:/Users/Phil/workspace/phpmelb
Starting a new project with Zend_Tool
Resulting directory structure
phpmelb
|-- 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
Web Application in a Can
Routes
Default route
:controller/:action/:param/:value/:param/:value...
// or (for modular applications)
:module/:controller/:action/:param/:value/:param/:value...
Custom routes provide ultimate flexibility
// typical “blog” route
:year/:month/:title/:page=1
// with the following defaults
:controller = “article”
:action = “read”
A “module” is simply a collection of controllers, views and custom helper objects.
Plugin Architecture
● Zend Framework supports customisation
through class extension, interface
implementation and plugin loaders
● Plugin loaders let the framework know where to
find custom classes and when to use them
● Controller plugins provide hooks for executing
procedures at any stage in the dispatch cycle
Now for some of my favourites
● ContextSwitch Controller Action Helper
● AjaxContext Controller Action Helper
● Zend_Form
ContextSwitch Controller Action
Helper
● One controller action
● Multiple view scripts depending on “context”
● Actions may be assigned one or more contexts
● Context specified on request using “format”
parameter
● Built-in contexts include
● XML
● JSON
● Developers may add custom contexts
ContextSwitch Helper Example
// application/controllers/IndexController.php
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->contextSwitch->addActionContext('index', 'xml')
->initContext();
}
public function indexAction()
{
$this->view->foo = 'foo';
}
}
// application/views/scripts/index.phtml
// Request example “/index/index”
<p>Foo: <?php echo $this->escape($this->foo) ?></p>`
// application/views/scripts/index.xml.phtml
// Request example “/index/index/format/xml”
<root>
<foo><?php echo $this->escape($this->foo) ?></foo>
</root>
AjaxContext Controller Action
Helper
● Extends ContextSwitch Helper
● Adds “html” context
● Only fires on AJAX requests
● Detects using X_REQUESTED_WITH HTTP
header
● Disables any layouts
● Perfect for loading HTML “snippets”
AjaxContext Helper Example
// application/controllers/IndexController.php
class IndexController extends Zend_Controller_Action
{
public function init()
{
$this->_helper->ajaxContext->addActionContext('index', 'html')
->initContext();
}
public function indexAction()
{
$this->view->foo = 'foo';
}
}
// application/views/scripts/index.phtml
<table>
<tr>
<td>Foo</td>
<td><?php echo $this->escape($this->foo) ?></td>
</tr>
</table>
// application/views/scripts/index.ajax.phtml
// Only the output below is sent in the response
<td>Foo</td>
<td><?php echo $this->escape($this->foo) ?></td>
Zend_Form
● One of the most powerful web application
development components
● Combines
● Form HTML generation
● Input filtering
● Input validation
● AJAX validation for client-side hooks
● Internationalisation
● Error handling and message display
Building Forms
● Forms can be built in code or from config files
● XML
● .ini
● PHP Array
● Form appearance dictated by “decorators”
● Decorators provide infinite markup possibilities
without effecting form logic
Zend_Form Example
$form = new Zend_Form;
$form->addElement('text', 'foo', array(
'label' => 'Foo',
'required' => true,
'filters' => array('StringTrim')
))->addElement('textarea', 'bar', array(
'label' => 'Bar',
'cols' => 60,
'rows' => 5,
'validators' => array(
array('StringLength', false, array(0, 50))
)
))->addElement('submit', 'submit_btn', array(
'label' => 'Submit'
))->addDisplayGroup(
array('foo', 'bar', 'submit_btn'),
'my_fieldset',
array('legend' => 'My Form')
);
Zend_Form Example
Validators In Action

More Related Content

PDF
MVC with Zend Framework
webholics
 
PPTX
Zend MVC pattern based Framework – Best for Enterprise web applications
Etisbew Technology Group
 
PPT
Zend framework 02 - mvc
Tricode (part of Dept)
 
PPT
Code igniter overview
umesh patil
 
PDF
MVC 1.0 als alternative Webtechnologie
OPEN KNOWLEDGE GmbH
 
ODP
A Good PHP Framework For Beginners Like Me!
Muhammad Ghazali
 
PDF
Require.JS
Ivano Malavolta
 
PDF
Asp 1-mvc introduction
Fajar Baskoro
 
MVC with Zend Framework
webholics
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Etisbew Technology Group
 
Zend framework 02 - mvc
Tricode (part of Dept)
 
Code igniter overview
umesh patil
 
MVC 1.0 als alternative Webtechnologie
OPEN KNOWLEDGE GmbH
 
A Good PHP Framework For Beginners Like Me!
Muhammad Ghazali
 
Require.JS
Ivano Malavolta
 
Asp 1-mvc introduction
Fajar Baskoro
 

What's hot (20)

PPTX
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Tom Walker
 
PDF
Mastering asp.net mvc - Dot Net Tricks
Gaurav Singh
 
PPTX
ASP .NET MVC
eldorina
 
ODP
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
 
PPT
ColdFusion framework comparison
VIkas Patel
 
PPTX
Exploring AngularJS - Liju Pillai
Liju Pillai
 
PPTX
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
Perfomatix Solutions
 
PPTX
Introduction to CodeIgniter
Piti Suwannakom
 
PPSX
RequireJS
Tim Doherty
 
PDF
Introduction To CodeIgniter
Muhammad Hafiz Hasan
 
PDF
Ch. 11 deploying
Manolis Vavalis
 
PPTX
Session 28 - Servlets - Part 4
PawanMM
 
PPTX
Having fun with code igniter
Ahmad Arif
 
PPT
Require JS
Imaginea
 
PPTX
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
PPTX
asp-net.pptx
Fajar Baskoro
 
PPTX
4. Introduction to ASP.NET MVC - Part I
Rohit Rao
 
PPTX
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
PDF
PHP MVC Tutorial
Yang Bruce
 
PDF
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Tom Walker
 
Mastering asp.net mvc - Dot Net Tricks
Gaurav Singh
 
ASP .NET MVC
eldorina
 
Burlington, VT PHP Users Group Subversion Presentation
Bradley Holt
 
ColdFusion framework comparison
VIkas Patel
 
Exploring AngularJS - Liju Pillai
Liju Pillai
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
Perfomatix Solutions
 
Introduction to CodeIgniter
Piti Suwannakom
 
RequireJS
Tim Doherty
 
Introduction To CodeIgniter
Muhammad Hafiz Hasan
 
Ch. 11 deploying
Manolis Vavalis
 
Session 28 - Servlets - Part 4
PawanMM
 
Having fun with code igniter
Ahmad Arif
 
Require JS
Imaginea
 
ASP.NET MVC 5 - EF 6 - VS2015
Hossein Zahed
 
asp-net.pptx
Fajar Baskoro
 
4. Introduction to ASP.NET MVC - Part I
Rohit Rao
 
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
PHP MVC Tutorial
Yang Bruce
 
Sightly - AEM6 UI Development using JS and JAVA
Yash Mody
 
Ad

Similar to Building Web Applications with Zend Framework (20)

PPT
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
PDF
Zend Framework Quick Start Walkthrough
Bradley Holt
 
ODP
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
King Foo
 
PPTX
Building and managing applications fast for IBM i
Zend by Rogue Wave Software
 
PDF
Memphis php 01 22-13 - laravel basics
Joe Ferguson
 
PPS
Simplify your professional web development with symfony
Francois Zaninotto
 
PDF
Drupal 8 - Core and API Changes
Shabir Ahmad
 
KEY
Improving QA on PHP projects - confoo 2011
Michelangelo van Dam
 
PPT
Laravel & Composer presentation - WebHostFace
Cvetomir Denchev
 
PPTX
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
ODP
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
PPT
Red5 - PHUG Workshops
Brendan Sera-Shriar
 
PPT
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
PPT
Laravel & Composer presentation - extended
Cvetomir Denchev
 
PPTX
PHP
Jawhar Ali
 
PPT
Getting Started with Zend Framework
Juan Antonio
 
ODP
Routing
Glenn Guden
 
PDF
Headless approach for offloading heavy tasks in Magento
Sander Mangel
 
PDF
Intro to drupal_7_architecture
Hai Vo Hoang
 
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
Zend Framework Quick Start Walkthrough
Bradley Holt
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
King Foo
 
Building and managing applications fast for IBM i
Zend by Rogue Wave Software
 
Memphis php 01 22-13 - laravel basics
Joe Ferguson
 
Simplify your professional web development with symfony
Francois Zaninotto
 
Drupal 8 - Core and API Changes
Shabir Ahmad
 
Improving QA on PHP projects - confoo 2011
Michelangelo van Dam
 
Laravel & Composer presentation - WebHostFace
Cvetomir Denchev
 
REST API Best Practices & Implementing in Codeigniter
Sachin G Kulkarni
 
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Red5 - PHUG Workshops
Brendan Sera-Shriar
 
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Laravel & Composer presentation - extended
Cvetomir Denchev
 
Getting Started with Zend Framework
Juan Antonio
 
Routing
Glenn Guden
 
Headless approach for offloading heavy tasks in Magento
Sander Mangel
 
Intro to drupal_7_architecture
Hai Vo Hoang
 
Ad

Recently uploaded (20)

PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Architecture of the Future (09152021)
EdwardMeyman
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Architecture of the Future (09152021)
EdwardMeyman
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
Beyond Automation: The Role of IoT Sensor Integration in Next-Gen Industries
Rejig Digital
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
ChatGPT's Deck on The Enduring Legacy of Fax Machines
Greg Swan
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Doc9.....................................
SofiaCollazos
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 

Building Web Applications with Zend Framework

  • 1. 19/10/09 Building Web Applications with Zend Framework 1 Building Web Applications with Zend Framework
  • 2. What is Zend Framework? ● A library of useful tools and classes? ● An MVC application framework? ● BOTH
  • 3. Zend Framework Library ● Yes, it's a little like PEAR ● Huge active community ● High quality code ● Object Oriented PHP5 ● Extensively tested
  • 4. Zend Framework Library ● Advanced, loosely coupled toolset covering a vast range of utilities, for example Database Abstraction Table data gateway pattern Cache Google Data API Adobe AMF Server HTTP Client LDAP Email OpenID PDF REST Client & Server Lucene Search SOAP Internationalisation XMLRPC
  • 5. Zend Application Framework ● MVC Design Pattern ● Rapid application development using Zend_Tool command line utility ● Convention over configuration defaults to a somewhat verbose directory structure however flexibility allows developers choice ● Features include SEF URLS, custom routes, context switching and a strong plugin architecture
  • 6. Zend Application Framework ● Helper objects are one of the highlights of the application framework ● Controller Action Helpers for various controller tasks – URL generation and redirection – Context Switching – Flash (single use) messaging ● View Helpers for visual / output encapsulation – HTML generation – Pagination – Navigation
  • 7. MVC Dispatch Overview Request Front Controller Controller Plugins ControllerModels Controller Action Helpers View View Helpers Layout Response
  • 8. Zend_Tool ● Zend_Tool can be used to ● Create projects ● Add modules, controllers, actions and views using the default ZF directory structure ● Show information about projects and the PHP environment
  • 9. Some Examples C:UsersPhilworkspace>zf create project phpmelb Creating project at C:/Users/Phil/workspace/phpmelb Starting a new project with Zend_Tool Resulting directory structure phpmelb |-- 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
  • 11. Routes Default route :controller/:action/:param/:value/:param/:value... // or (for modular applications) :module/:controller/:action/:param/:value/:param/:value... Custom routes provide ultimate flexibility // typical “blog” route :year/:month/:title/:page=1 // with the following defaults :controller = “article” :action = “read” A “module” is simply a collection of controllers, views and custom helper objects.
  • 12. Plugin Architecture ● Zend Framework supports customisation through class extension, interface implementation and plugin loaders ● Plugin loaders let the framework know where to find custom classes and when to use them ● Controller plugins provide hooks for executing procedures at any stage in the dispatch cycle
  • 13. Now for some of my favourites ● ContextSwitch Controller Action Helper ● AjaxContext Controller Action Helper ● Zend_Form
  • 14. ContextSwitch Controller Action Helper ● One controller action ● Multiple view scripts depending on “context” ● Actions may be assigned one or more contexts ● Context specified on request using “format” parameter ● Built-in contexts include ● XML ● JSON ● Developers may add custom contexts
  • 15. ContextSwitch Helper Example // application/controllers/IndexController.php class IndexController extends Zend_Controller_Action { public function init() { $this->_helper->contextSwitch->addActionContext('index', 'xml') ->initContext(); } public function indexAction() { $this->view->foo = 'foo'; } } // application/views/scripts/index.phtml // Request example “/index/index” <p>Foo: <?php echo $this->escape($this->foo) ?></p>` // application/views/scripts/index.xml.phtml // Request example “/index/index/format/xml” <root> <foo><?php echo $this->escape($this->foo) ?></foo> </root>
  • 16. AjaxContext Controller Action Helper ● Extends ContextSwitch Helper ● Adds “html” context ● Only fires on AJAX requests ● Detects using X_REQUESTED_WITH HTTP header ● Disables any layouts ● Perfect for loading HTML “snippets”
  • 17. AjaxContext Helper Example // application/controllers/IndexController.php class IndexController extends Zend_Controller_Action { public function init() { $this->_helper->ajaxContext->addActionContext('index', 'html') ->initContext(); } public function indexAction() { $this->view->foo = 'foo'; } } // application/views/scripts/index.phtml <table> <tr> <td>Foo</td> <td><?php echo $this->escape($this->foo) ?></td> </tr> </table> // application/views/scripts/index.ajax.phtml // Only the output below is sent in the response <td>Foo</td> <td><?php echo $this->escape($this->foo) ?></td>
  • 18. Zend_Form ● One of the most powerful web application development components ● Combines ● Form HTML generation ● Input filtering ● Input validation ● AJAX validation for client-side hooks ● Internationalisation ● Error handling and message display
  • 19. Building Forms ● Forms can be built in code or from config files ● XML ● .ini ● PHP Array ● Form appearance dictated by “decorators” ● Decorators provide infinite markup possibilities without effecting form logic
  • 20. Zend_Form Example $form = new Zend_Form; $form->addElement('text', 'foo', array( 'label' => 'Foo', 'required' => true, 'filters' => array('StringTrim') ))->addElement('textarea', 'bar', array( 'label' => 'Bar', 'cols' => 60, 'rows' => 5, 'validators' => array( array('StringLength', false, array(0, 50)) ) ))->addElement('submit', 'submit_btn', array( 'label' => 'Submit' ))->addDisplayGroup( array('foo', 'bar', 'submit_btn'), 'my_fieldset', array('legend' => 'My Form') );