SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
eldorina
 
ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparison
VIkas Patel
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
Jon Galloway
 
PHP MVC Tutorial
PHP MVC TutorialPHP MVC Tutorial
PHP MVC Tutorial
Yang Bruce
 

Tendances (20)

Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazingMortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing
 
Mastering asp.net mvc - Dot Net Tricks
Mastering asp.net mvc - Dot Net TricksMastering asp.net mvc - Dot Net Tricks
Mastering asp.net mvc - Dot Net Tricks
 
ASP .NET MVC
ASP .NET MVC ASP .NET MVC
ASP .NET MVC
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 
ColdFusion framework comparison
ColdFusion framework comparisonColdFusion framework comparison
ColdFusion framework comparison
 
Exploring AngularJS - Liju Pillai
Exploring AngularJS - Liju PillaiExploring AngularJS - Liju Pillai
Exploring AngularJS - Liju Pillai
 
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.comWhen to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
When to use and when not to use AngularJS - Liju Pillai, www.perfomatix.com
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
RequireJS
RequireJSRequireJS
RequireJS
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Ch. 11 deploying
Ch. 11 deployingCh. 11 deploying
Ch. 11 deploying
 
Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4Session 28 - Servlets - Part 4
Session 28 - Servlets - Part 4
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Require JS
Require JSRequire JS
Require JS
 
ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015ASP.NET MVC 5 - EF 6 - VS2015
ASP.NET MVC 5 - EF 6 - VS2015
 
asp-net.pptx
asp-net.pptxasp-net.pptx
asp-net.pptx
 
4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I4. Introduction to ASP.NET MVC - Part I
4. Introduction to ASP.NET MVC - Part I
 
SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5SoCal Code Camp 2011 - ASP.NET 4.5
SoCal Code Camp 2011 - ASP.NET 4.5
 
PHP MVC Tutorial
PHP MVC TutorialPHP MVC Tutorial
PHP MVC Tutorial
 
Sightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVASightly - AEM6 UI Development using JS and JAVA
Sightly - AEM6 UI Development using JS and JAVA
 

Similaire à Building Web Applications with Zend Framework

Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
Ganesh Kulkarni
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
King Foo
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
PHP
PHPPHP

Similaire à Building Web Applications with Zend Framework (20)

Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basics
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011
 
Laravel & Composer presentation - WebHostFace
Laravel & Composer presentation - WebHostFace Laravel & Composer presentation - WebHostFace
Laravel & Composer presentation - WebHostFace
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Red5 - PHUG Workshops
Red5 - PHUG WorkshopsRed5 - PHUG Workshops
Red5 - PHUG Workshops
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extended
 
PHP
PHPPHP
PHP
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
Routing
RoutingRouting
Routing
 
Headless approach for offloading heavy tasks in Magento
Headless approach for offloading heavy tasks in MagentoHeadless approach for offloading heavy tasks in Magento
Headless approach for offloading heavy tasks in Magento
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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