0
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
●...
Zend Framework Library
● Advanced, loosely coupled toolset covering a
vast range of utilities, for example
Database Abstra...
Zend Application Framework
● MVC Design Pattern
● Rapid application development using
Zend_Tool command line utility
● Con...
Zend Application Framework
● Helper objects are one of the highlights of the
application framework
● Controller Action Hel...
MVC Dispatch Overview
Request
Front Controller
Controller
Plugins
ControllerModels
Controller
Action Helpers
View
View Hel...
Zend_Tool
● Zend_Tool can be used to
● Create projects
● Add modules, controllers, actions and views using
the default ZF ...
Some Examples
C:UsersPhilworkspace>zf create project phpmelb
Creating project at C:/Users/Phil/workspace/phpmelb
Starting ...
Web Application in a Can
Routes
Default route
:controller/:action/:param/:value/:param/:value...
// or (for modular applications)
:module/:controll...
Plugin Architecture
● Zend Framework supports customisation
through class extension, interface
implementation and plugin l...
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 ma...
ContextSwitch Helper Example
// application/controllers/IndexController.php
class IndexController extends Zend_Controller_...
AjaxContext Controller Action
Helper
● Extends ContextSwitch Helper
● Adds “html” context
● Only fires on AJAX requests
● ...
AjaxContext Helper Example
// application/controllers/IndexController.php
class IndexController extends Zend_Controller_Ac...
Zend_Form
● One of the most powerful web application
development components
● Combines
● Form HTML generation
● Input filt...
Building Forms
● Forms can be built in code or from config files
● XML
● .ini
● PHP Array
● Form appearance dictated by “d...
Zend_Form Example
$form = new Zend_Form;
$form->addElement('text', 'foo', array(
'label' => 'Foo',
'required' => true,
'fi...
Zend_Form Example
Validators In Action
Upcoming SlideShare
Loading in...5
×

Building Web Applications with Zend Framework

1,138

Published on

This presentation contains a brief overview of Zend Framework and some of the features I find useful as a web application developer

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,138
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
58
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Building Web Applications with Zend Framework"

  1. 1. 19/10/09 Building Web Applications with Zend Framework 1 Building Web Applications with Zend Framework
  2. 2. What is Zend Framework? ● A library of useful tools and classes? ● An MVC application framework? ● BOTH
  3. 3. Zend Framework Library ● Yes, it's a little like PEAR ● Huge active community ● High quality code ● Object Oriented PHP5 ● Extensively tested
  4. 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. 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. 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. 7. MVC Dispatch Overview Request Front Controller Controller Plugins ControllerModels Controller Action Helpers View View Helpers Layout Response
  8. 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. 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
  10. 10. Web Application in a Can
  11. 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. 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. 13. Now for some of my favourites ● ContextSwitch Controller Action Helper ● AjaxContext Controller Action Helper ● Zend_Form
  14. 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. 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. 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. 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. 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. 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. 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') );
  21. 21. Zend_Form Example
  22. 22. Validators In Action
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×