SlideShare a Scribd company logo
Zend Framework MVC Quick Start Matthew Weier O'Phinney PHP Developer Zend Technologies Irmantas Šiupšinskas   Zend Framework provides rich and flexible MVC components built using the object-oriented features of PHP 5.
Topics Overview Zend Framework Overview What is MVC? Zend_Controller: The 'C' in MVC Zend_View: The 'V' in MVC Zend_... Where's the 'M'? Putting it Together Q & A 9 Oct 2007 | Page
Zend Framework Zend Framework Overview 9 Oct 2007 | Page
What is Zend Framework? Component Library Loosely coupled components for general purpose actions Use-at-will architecture Application Framework Cohesive framework for building applications 9 Oct 2007 | Page
Zend Framework Goals Extreme Simplicity: Simpler is easier to use Simpler is more stable and less prone to error Simpler is easier to maintain 9 Oct 2007 | Page
Zend Framework Goals Showcase Current Trends: Web Services Ajax Search 9 Oct 2007 | Page
Zend Framework Goals Stability and Documentation All components must have > 80% test coverage All components must have end-user documentation and use-cases 9 Oct 2007 | Page
Zend Framework Goals Business Friendly Contributor License Agreement required in order to contribute code, patches, or documentation All code licensed under the new BSD license 9 Oct 2007 | Page
Zend Framework What is MVC? 9 Oct 2007 | Page
MVC Overview Model The "stuff" you are using in the application -- data, web services, feeds, etc. View The display returned to the user. Controller Manages the request environment, and determines what happens. 9 Oct 2007 | Page
MVC Interactions Controller <-> View Controller and View can interact Controller <-> Model Controller can pull data from the model for decisioning, or push data to the model View <- Model View can access the model to retrieve data, but not write to it. 9 Oct 2007 | Page
Front Controller Handles all requests Delegates requests to 'Action Controllers' for handling Returns response 9 Oct 2007 | Page
Zend Framework Zend_Controller: The 'C' in MVC 9 Oct 2007 | Page
Zend_Controller: Basics Action Controllers: Extend Zend_Controller_Action Class name ends in 'Controller' IndexController BlogController Underscores indicate directory separators Foo_AdminController => Foo/AdminController.php Note: rule is different with modules CamelCasing allowed FooBarController Separate CamelCased words in URLS with '-' or '.': foo-bar foo.bar 9 Oct 2007 | Page
Zend_Controller: Basics Controller Actions: Method the action controller should perform Public methods ending in 'Action' barAction()‏ indexAction()‏ CamelCasing allowed fooBarAction()‏ Separate camelCased words on the URL with '.', '-', or '_': foo-bar foo.bar foo_bar 9 Oct 2007 | Page
Zend_Controller: Basics Modules: A set of related action controllers, models, and views Directory structure mimics application directory structure: controllers/ models/ views/ Controller class names should be prefixed with module name: Foo_ViewController -> foo/controllers/ViewController.php Module names may be camelCased as well; follow rules for controllers 9 Oct 2007 | Page
Zend_Controller: Responsibilities Request object:  contains all information on the request environment Router:  decomposes environment into various tokens representing the current module, controller, action, etc. Dispatcher:  maps the tokens from routing to action controller classes and methods, and executes them Response object:  contains the complete response and has the ability to send it 9 Oct 2007 | Page
Zend_Controller: Process Diagam 9 Oct 2007 | Page
Zend_Controller: Dispatch Loop $front->dispatch() handles the incoming request Instantiates request and response objects if not previously set Routes request Enters dispatch loop Dispatch Action Instantiate controller Call action method Dispatches until request object reports no more actions to dispatch Returns Response (sends by default)‏ 9 Oct 2007 | Page
Zend_Controller: Routing Default Routing: /controller/action /controller/action/key1/value1/key2/value2 /module/controller/action /module/controller/action/key1/value1/... 9 Oct 2007 | Page
Zend_Controller: Routing Modifying Routing: Rewrite Router: Zend_Controller_Router_Rewrite is the default router implementation Allows attaching as many named routes as desired Named routes allow pulling routes for later operations, such as URL assembly or determining what in a URL matched. Routes are executed in a LIFO order Route interface allows defining your own route types for your applications 9 Oct 2007 | Page
Zend_Controller: Routing Shipped Route Types: Static: match exactly, and dispatch according to defaults Fastest route; straight equality comparison Standard: matches by named URL segments Flexible and readable, easiest creation of dynamic routes. However, each URL segment is potentially compared against a regexp, making it slow. Regex: matches using PCRE Fastest and most flexible dynamic route, but potentially the hardest to maintain if not all developers are equally versed in PCRE. 9 Oct 2007 | Page
Zend_Controller: Routing Creating a new route: Want to match this: /news/view/12 Route: /news/view/:id 9 Oct 2007 | Page
Zend_Controller: Action Controllers Action Controllers Simply classes that extend Zend_Controller_Action Define public action methods for each action you want the controller to handle Use regular public methods when you want to have re-usable or testable functionality 9 Oct 2007 | Page
Zend_Controller: Action Controllers Action controller triggers and listens to the following events: init():  object instantiation preDispatch():  prior to dispatching the action postDispatch():  after the action has executed 9 Oct 2007 | Page
Zend_Controller: Action Controllers Utility Methods: _forward($action, $controller = null, $module = null, array $params = null):  forward to another action _redirect($url):  redirect to another location render($action, $name, $noController): render an alternate view script __call($method, $params):  use to create 'dynamic' actions or internally forward to a default action 9 Oct 2007 | Page
Zend_Controller: ViewRenderer View integration is automatically available  Registered by  ViewRenderer  action helper Can be disabled $view property of controller contains view object Assign variables to view:  $this->view->model = $model; 9 Oct 2007 | Page
Zend_Controller: ViewRenderer View scripts are rendered automatically during postDispatch() event View scripts named after controller and action: FooController::barAction() renders foo/bar.phtml NewsController::listAction() renders news/list.phtml Disabling the ViewRenderer setNoRender() will disable it for the current action Calling _forward() or _redirect() never auto-renders 9 Oct 2007 | Page
Zend_Controller: ViewRenderer Customizing the ViewRenderer: setView()‏ Set view object (allows for custom view implementations!)‏ setViewSuffix()‏ Change the file suffix used setView(Base|Script)PathSpec()‏ Set the path specification used for auto-determining the view location setResponseSegment()‏ Set the named response segment to render into 9 Oct 2007 | Page
Zend_Controller Sample Action Controller: 9 Oct 2007 | Page
Zend_Controller: Plugins What are Plugins? Triggered by front controller events Events bookend each major process of the front controller Allow automating actions that apply globally 9 Oct 2007 | Page
Zend_Controller: Plugins Events: routeStartup():  prior to routing routeShutdown():  after routing dispatchLoopStartup():  prior to fist iteration of dispatch loop preDispatch():  prior to dispatching an action postDispatch():  after dispatching an action dispatchLoopShutdown():  at dispatch loop termination 9 Oct 2007 | Page
Zend_Controller: Plugins Creating Plugins: Extend Zend_Controller_Plugin_Abstract Extend one or more of the event methods Create multi-purpose plugins by extending multiple methods Create targetted plugins by extending a single method 9 Oct 2007 | Page
Zend_Controller: Plugins Example: Two-Step View Plugin 9 Oct 2007 | Page  Note: the above will be superseded shortly by Zend_Layout
Zend_Controller: Action Helpers What are Action Helpers? Reusable functionality Functionality that can be used in multiple controllers Functionality you want to be able to discretely unit test Objects you wish to persist across controllers Useful for automating processes that involve the action controllers Initialized on-demand, or may be registered with helper broker Functionality you may want to swap out later 9 Oct 2007 | Page
Zend_Controller: Action Helpers Creating Action Helpers: Extend  Zend_Controller_Action_Helper_Abstract Last segment of class name is helper name My_Helper_Foo -> 'foo' helper My_Helper_FooBar -> 'fooBar' helper Optionally implement a direct() method for method-like invocation Allows helper to be called as if it were a method of the helper broker 9 Oct 2007 | Page
Zend_Controller: Action Helpers Using Action Helpers as Action Controller Event Listeners: init(): when the action controller is initialized preDispatch():  executes after front controller preDispatch() plugins but before action controller preDispatch postDispatch()  executes after action controller postDispatch() but before front controller postDispatch() plugins Note: helper must be registered with broker for events to trigger 9 Oct 2007 | Page
Zend Framework Zend_View:  The 'V' in MVC 9 Oct 2007 | Page
Zend_View: Overview Implement  Zend_View_Interface  to create your own template engine Default implementation ( Zend_View ) uses PHP as the template language Assign and retrieve view variables as if they were object members:  $view->content = $body Access view variables in view scripts from  $this  object:  <?= $this->content ?> Benefits: All of PHP is at your disposal Issues: All of PHP is at your disposal 9 Oct 2007 | Page
Zend_View: View Scripts Mix HTML and PHP Access template variables using  $this  notation Keeps assigned variables in their own scope Easily distinguish assigned variables from local variables Easy placeholder implementation: simply assign from view scripts and use in later view scripts 9 Oct 2007 | Page
Zend_View: View Scripts Use PHP short tags for shorthand notation: 9 Oct 2007 | Page
Zend_View: View Helpers Classes that extend the functionality of Zend_View Uses Access models (e.g. add a del.icio.us feed to your page)‏ Format or escape output (e.g. transform wiki text to XHTML)‏ Display logic (e.g., show login buttons if user not logged in)‏ Re-usable display snippets (e.g., search form box)‏ 9 Oct 2007 | Page
Zend_View: View Helpers Using View Helpers: Call as if the helper were a method of the view object <?= $this->formText('username') ?> 9 Oct 2007 | Page
Zend_View: View Helpers Creating and Using View Helper: Helper name is last segment of class name My_View_Helpers_Foo: foo helper My_View_Helpers_FooBar: fooBar helper Register helper paths with Zend_View object Optionally specify a class prefix Paths searched in LIFO order Override a helper by registering late 9 Oct 2007 | Page
Zend_View: View Helpers View Helper Classes: Must have a method named after the helper: 9 Oct 2007 | Page
Zend_View: View Helpers Optionally allow view awareness by creating a setView() method: 9 Oct 2007 | Page
Zend_View: Filters Allow filtering rendered content prior to returning it Similar to helpers, one class and method per filter Use Cases Transform HTML to PDF Transform HTML to JSON Pass X/HTML through tidy Inject session IDs 9 Oct 2007 | Page
Zend Framework Zend_...:  Where's the 'M'? 9 Oct 2007 | Page
Zend_Model? What is a Model? Database Web Services Feeds Configuration files Filesystem Images 9 Oct 2007 | Page
Zend_Model? How does Zend Framework address the Model? We don't yet, at least not as a generalized component.  But we do support it with our specialized components: Zend_Db_Table Zend_Service Zend_Feed etc. 9 Oct 2007 | Page
Zend Framework Putting it Together 9 Oct 2007 | Page
Putting it Together Filesystem Layout: 9 Oct 2007 | Page
Putting it Together The Bootstrap file (index.php): Simplest: 9 Oct 2007 | Page
Putting it Together Bootstrap klasė (Bootsrap.php) 9 Oct 2007 | Page
Putting it Together Hello World! IndexController: 9 Oct 2007 | Page
Putting it Together Hello World! ErrorController: 9 Oct 2007 | Page
Putting it Together Hello World! View scripts: 9 Oct 2007 | Page
Thank you! More on Zend Framework: http://framework.zend.com

More Related Content

KEY
Extending Zend_Tool
PPT
Using Zend_Tool to Establish Your Project's Skeleton
ODP
When dynamic becomes static
PPT
Zend Framework Introduction
PDF
Deprecated: Foundations of Zend Framework 2
PDF
A quick start on Zend Framework 2
ODP
Introduction to Zend Framework
PDF
Zend Framework 2 quick start
Extending Zend_Tool
Using Zend_Tool to Establish Your Project's Skeleton
When dynamic becomes static
Zend Framework Introduction
Deprecated: Foundations of Zend Framework 2
A quick start on Zend Framework 2
Introduction to Zend Framework
Zend Framework 2 quick start

What's hot (19)

PPTX
Hibernate
PPT
Zend Framework 2
ODP
Java Code Generation for Productivity
PPT
Edp bootstrapping a-software_company
PDF
Java Enterprise Edition
PDF
Zend Framework 2 - Basic Components
PDF
Zend Framework 2 Components
PDF
.NET Core, ASP.NET Core Course, Session 12
PPT
Apache Ant
PDF
Apache DeltaSpike the CDI toolbox
PDF
.NET Core, ASP.NET Core Course, Session 16
PDF
Drupal8 for Symfony Developers (PHP Day Verona 2017)
PPTX
Rest and Sling Resolution
PPTX
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
PDF
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
PPT
Ant - Another Neat Tool
PDF
Spring - CDI Interop
PDF
Spring 4 on Java 8 by Juergen Hoeller
Hibernate
Zend Framework 2
Java Code Generation for Productivity
Edp bootstrapping a-software_company
Java Enterprise Edition
Zend Framework 2 - Basic Components
Zend Framework 2 Components
.NET Core, ASP.NET Core Course, Session 12
Apache Ant
Apache DeltaSpike the CDI toolbox
.NET Core, ASP.NET Core Course, Session 16
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Rest and Sling Resolution
JavaOne - 10 Tips for Java EE 7 with PrimeFaces
Kicking off with Zend Expressive and Doctrine ORM (PHPNW2016)
Ant - Another Neat Tool
Spring - CDI Interop
Spring 4 on Java 8 by Juergen Hoeller
Ad

Viewers also liked (20)

PPTX
Prototyping app using JS and HTML5 (Ciklum Kharkiv)
PPT
Page Rank
PPT
abrag
PPT
Miyagawa
PPT
Pascale Perry - #smib10 Presentation
PPTX
Technology Products as Timeshare VS Reading and Sports
PDF
Shannons Ink And Pencil
PPTX
WEB Taikomųjų Programų Kūrimas
PDF
Presentation1
PPT
Greenpeace
PPTX
PPTX
Mitä mun puhelin osaa010316
PPTX
sosiaalisen median mahdollisuudet opetuksessa
PPT
euroFOT Aachener Kolloquium, Ford
PDF
Executive Warfare
PPT
PDF
How stupid can we get
PPT
Del ocio para el ocio
PDF
Rapport - hvordan norske virksomheter jobber med employer branding
Prototyping app using JS and HTML5 (Ciklum Kharkiv)
Page Rank
abrag
Miyagawa
Pascale Perry - #smib10 Presentation
Technology Products as Timeshare VS Reading and Sports
Shannons Ink And Pencil
WEB Taikomųjų Programų Kūrimas
Presentation1
Greenpeace
Mitä mun puhelin osaa010316
sosiaalisen median mahdollisuudet opetuksessa
euroFOT Aachener Kolloquium, Ford
Executive Warfare
How stupid can we get
Del ocio para el ocio
Rapport - hvordan norske virksomheter jobber med employer branding
Ad

Similar to 2007 Zend Con Mvc Edited Irmantas (20)

PPT
2007 Zend Con Mvc
ODP
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
PDF
Express node js
PDF
Foundations of Zend Framework
PPT
Getting Started with Zend Framework
PDF
Rupicon 2014 Action pack
ODP
Zend Framework 1.9 Setup & Using Zend_Tool
PPTX
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
PDF
Mvc interview questions – deep dive jinal desai
PPTX
Asp.net mvc
PPTX
Controllers & actions
DOCX
Implementing a file manager in ASP.NET Core 8.0
ODP
Http programming in play
PDF
Building Web Applications with Zend Framework
ODP
Spring Portlet MVC
PDF
Rest web service_with_spring_hateoas
PDF
Learn Drupal 8 Render Pipeline
PPT
Dn D Custom 1
PPT
Dn D Custom 1
PPTX
Meteor Meet-up San Diego December 2014
2007 Zend Con Mvc
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Express node js
Foundations of Zend Framework
Getting Started with Zend Framework
Rupicon 2014 Action pack
Zend Framework 1.9 Setup & Using Zend_Tool
New features of Minimal APIs in .NET 7 -Muralidharan Deenathayalan.pptx
Mvc interview questions – deep dive jinal desai
Asp.net mvc
Controllers & actions
Implementing a file manager in ASP.NET Core 8.0
Http programming in play
Building Web Applications with Zend Framework
Spring Portlet MVC
Rest web service_with_spring_hateoas
Learn Drupal 8 Render Pipeline
Dn D Custom 1
Dn D Custom 1
Meteor Meet-up San Diego December 2014

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
A Presentation on Artificial Intelligence
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Modernizing your data center with Dell and AMD
Cloud computing and distributed systems.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Review of recent advances in non-invasive hemoglobin estimation
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
Modernizing your data center with Dell and AMD

2007 Zend Con Mvc Edited Irmantas

  • 1. Zend Framework MVC Quick Start Matthew Weier O'Phinney PHP Developer Zend Technologies Irmantas Šiupšinskas  Zend Framework provides rich and flexible MVC components built using the object-oriented features of PHP 5.
  • 2. Topics Overview Zend Framework Overview What is MVC? Zend_Controller: The 'C' in MVC Zend_View: The 'V' in MVC Zend_... Where's the 'M'? Putting it Together Q & A 9 Oct 2007 | Page
  • 3. Zend Framework Zend Framework Overview 9 Oct 2007 | Page
  • 4. What is Zend Framework? Component Library Loosely coupled components for general purpose actions Use-at-will architecture Application Framework Cohesive framework for building applications 9 Oct 2007 | Page
  • 5. Zend Framework Goals Extreme Simplicity: Simpler is easier to use Simpler is more stable and less prone to error Simpler is easier to maintain 9 Oct 2007 | Page
  • 6. Zend Framework Goals Showcase Current Trends: Web Services Ajax Search 9 Oct 2007 | Page
  • 7. Zend Framework Goals Stability and Documentation All components must have > 80% test coverage All components must have end-user documentation and use-cases 9 Oct 2007 | Page
  • 8. Zend Framework Goals Business Friendly Contributor License Agreement required in order to contribute code, patches, or documentation All code licensed under the new BSD license 9 Oct 2007 | Page
  • 9. Zend Framework What is MVC? 9 Oct 2007 | Page
  • 10. MVC Overview Model The &quot;stuff&quot; you are using in the application -- data, web services, feeds, etc. View The display returned to the user. Controller Manages the request environment, and determines what happens. 9 Oct 2007 | Page
  • 11. MVC Interactions Controller <-> View Controller and View can interact Controller <-> Model Controller can pull data from the model for decisioning, or push data to the model View <- Model View can access the model to retrieve data, but not write to it. 9 Oct 2007 | Page
  • 12. Front Controller Handles all requests Delegates requests to 'Action Controllers' for handling Returns response 9 Oct 2007 | Page
  • 13. Zend Framework Zend_Controller: The 'C' in MVC 9 Oct 2007 | Page
  • 14. Zend_Controller: Basics Action Controllers: Extend Zend_Controller_Action Class name ends in 'Controller' IndexController BlogController Underscores indicate directory separators Foo_AdminController => Foo/AdminController.php Note: rule is different with modules CamelCasing allowed FooBarController Separate CamelCased words in URLS with '-' or '.': foo-bar foo.bar 9 Oct 2007 | Page
  • 15. Zend_Controller: Basics Controller Actions: Method the action controller should perform Public methods ending in 'Action' barAction()‏ indexAction()‏ CamelCasing allowed fooBarAction()‏ Separate camelCased words on the URL with '.', '-', or '_': foo-bar foo.bar foo_bar 9 Oct 2007 | Page
  • 16. Zend_Controller: Basics Modules: A set of related action controllers, models, and views Directory structure mimics application directory structure: controllers/ models/ views/ Controller class names should be prefixed with module name: Foo_ViewController -> foo/controllers/ViewController.php Module names may be camelCased as well; follow rules for controllers 9 Oct 2007 | Page
  • 17. Zend_Controller: Responsibilities Request object: contains all information on the request environment Router: decomposes environment into various tokens representing the current module, controller, action, etc. Dispatcher: maps the tokens from routing to action controller classes and methods, and executes them Response object: contains the complete response and has the ability to send it 9 Oct 2007 | Page
  • 18. Zend_Controller: Process Diagam 9 Oct 2007 | Page
  • 19. Zend_Controller: Dispatch Loop $front->dispatch() handles the incoming request Instantiates request and response objects if not previously set Routes request Enters dispatch loop Dispatch Action Instantiate controller Call action method Dispatches until request object reports no more actions to dispatch Returns Response (sends by default)‏ 9 Oct 2007 | Page
  • 20. Zend_Controller: Routing Default Routing: /controller/action /controller/action/key1/value1/key2/value2 /module/controller/action /module/controller/action/key1/value1/... 9 Oct 2007 | Page
  • 21. Zend_Controller: Routing Modifying Routing: Rewrite Router: Zend_Controller_Router_Rewrite is the default router implementation Allows attaching as many named routes as desired Named routes allow pulling routes for later operations, such as URL assembly or determining what in a URL matched. Routes are executed in a LIFO order Route interface allows defining your own route types for your applications 9 Oct 2007 | Page
  • 22. Zend_Controller: Routing Shipped Route Types: Static: match exactly, and dispatch according to defaults Fastest route; straight equality comparison Standard: matches by named URL segments Flexible and readable, easiest creation of dynamic routes. However, each URL segment is potentially compared against a regexp, making it slow. Regex: matches using PCRE Fastest and most flexible dynamic route, but potentially the hardest to maintain if not all developers are equally versed in PCRE. 9 Oct 2007 | Page
  • 23. Zend_Controller: Routing Creating a new route: Want to match this: /news/view/12 Route: /news/view/:id 9 Oct 2007 | Page
  • 24. Zend_Controller: Action Controllers Action Controllers Simply classes that extend Zend_Controller_Action Define public action methods for each action you want the controller to handle Use regular public methods when you want to have re-usable or testable functionality 9 Oct 2007 | Page
  • 25. Zend_Controller: Action Controllers Action controller triggers and listens to the following events: init(): object instantiation preDispatch(): prior to dispatching the action postDispatch(): after the action has executed 9 Oct 2007 | Page
  • 26. Zend_Controller: Action Controllers Utility Methods: _forward($action, $controller = null, $module = null, array $params = null): forward to another action _redirect($url): redirect to another location render($action, $name, $noController): render an alternate view script __call($method, $params): use to create 'dynamic' actions or internally forward to a default action 9 Oct 2007 | Page
  • 27. Zend_Controller: ViewRenderer View integration is automatically available Registered by ViewRenderer action helper Can be disabled $view property of controller contains view object Assign variables to view: $this->view->model = $model; 9 Oct 2007 | Page
  • 28. Zend_Controller: ViewRenderer View scripts are rendered automatically during postDispatch() event View scripts named after controller and action: FooController::barAction() renders foo/bar.phtml NewsController::listAction() renders news/list.phtml Disabling the ViewRenderer setNoRender() will disable it for the current action Calling _forward() or _redirect() never auto-renders 9 Oct 2007 | Page
  • 29. Zend_Controller: ViewRenderer Customizing the ViewRenderer: setView()‏ Set view object (allows for custom view implementations!)‏ setViewSuffix()‏ Change the file suffix used setView(Base|Script)PathSpec()‏ Set the path specification used for auto-determining the view location setResponseSegment()‏ Set the named response segment to render into 9 Oct 2007 | Page
  • 30. Zend_Controller Sample Action Controller: 9 Oct 2007 | Page
  • 31. Zend_Controller: Plugins What are Plugins? Triggered by front controller events Events bookend each major process of the front controller Allow automating actions that apply globally 9 Oct 2007 | Page
  • 32. Zend_Controller: Plugins Events: routeStartup(): prior to routing routeShutdown(): after routing dispatchLoopStartup(): prior to fist iteration of dispatch loop preDispatch(): prior to dispatching an action postDispatch(): after dispatching an action dispatchLoopShutdown(): at dispatch loop termination 9 Oct 2007 | Page
  • 33. Zend_Controller: Plugins Creating Plugins: Extend Zend_Controller_Plugin_Abstract Extend one or more of the event methods Create multi-purpose plugins by extending multiple methods Create targetted plugins by extending a single method 9 Oct 2007 | Page
  • 34. Zend_Controller: Plugins Example: Two-Step View Plugin 9 Oct 2007 | Page Note: the above will be superseded shortly by Zend_Layout
  • 35. Zend_Controller: Action Helpers What are Action Helpers? Reusable functionality Functionality that can be used in multiple controllers Functionality you want to be able to discretely unit test Objects you wish to persist across controllers Useful for automating processes that involve the action controllers Initialized on-demand, or may be registered with helper broker Functionality you may want to swap out later 9 Oct 2007 | Page
  • 36. Zend_Controller: Action Helpers Creating Action Helpers: Extend Zend_Controller_Action_Helper_Abstract Last segment of class name is helper name My_Helper_Foo -> 'foo' helper My_Helper_FooBar -> 'fooBar' helper Optionally implement a direct() method for method-like invocation Allows helper to be called as if it were a method of the helper broker 9 Oct 2007 | Page
  • 37. Zend_Controller: Action Helpers Using Action Helpers as Action Controller Event Listeners: init(): when the action controller is initialized preDispatch(): executes after front controller preDispatch() plugins but before action controller preDispatch postDispatch() executes after action controller postDispatch() but before front controller postDispatch() plugins Note: helper must be registered with broker for events to trigger 9 Oct 2007 | Page
  • 38. Zend Framework Zend_View: The 'V' in MVC 9 Oct 2007 | Page
  • 39. Zend_View: Overview Implement Zend_View_Interface to create your own template engine Default implementation ( Zend_View ) uses PHP as the template language Assign and retrieve view variables as if they were object members: $view->content = $body Access view variables in view scripts from $this object: <?= $this->content ?> Benefits: All of PHP is at your disposal Issues: All of PHP is at your disposal 9 Oct 2007 | Page
  • 40. Zend_View: View Scripts Mix HTML and PHP Access template variables using $this notation Keeps assigned variables in their own scope Easily distinguish assigned variables from local variables Easy placeholder implementation: simply assign from view scripts and use in later view scripts 9 Oct 2007 | Page
  • 41. Zend_View: View Scripts Use PHP short tags for shorthand notation: 9 Oct 2007 | Page
  • 42. Zend_View: View Helpers Classes that extend the functionality of Zend_View Uses Access models (e.g. add a del.icio.us feed to your page)‏ Format or escape output (e.g. transform wiki text to XHTML)‏ Display logic (e.g., show login buttons if user not logged in)‏ Re-usable display snippets (e.g., search form box)‏ 9 Oct 2007 | Page
  • 43. Zend_View: View Helpers Using View Helpers: Call as if the helper were a method of the view object <?= $this->formText('username') ?> 9 Oct 2007 | Page
  • 44. Zend_View: View Helpers Creating and Using View Helper: Helper name is last segment of class name My_View_Helpers_Foo: foo helper My_View_Helpers_FooBar: fooBar helper Register helper paths with Zend_View object Optionally specify a class prefix Paths searched in LIFO order Override a helper by registering late 9 Oct 2007 | Page
  • 45. Zend_View: View Helpers View Helper Classes: Must have a method named after the helper: 9 Oct 2007 | Page
  • 46. Zend_View: View Helpers Optionally allow view awareness by creating a setView() method: 9 Oct 2007 | Page
  • 47. Zend_View: Filters Allow filtering rendered content prior to returning it Similar to helpers, one class and method per filter Use Cases Transform HTML to PDF Transform HTML to JSON Pass X/HTML through tidy Inject session IDs 9 Oct 2007 | Page
  • 48. Zend Framework Zend_...: Where's the 'M'? 9 Oct 2007 | Page
  • 49. Zend_Model? What is a Model? Database Web Services Feeds Configuration files Filesystem Images 9 Oct 2007 | Page
  • 50. Zend_Model? How does Zend Framework address the Model? We don't yet, at least not as a generalized component. But we do support it with our specialized components: Zend_Db_Table Zend_Service Zend_Feed etc. 9 Oct 2007 | Page
  • 51. Zend Framework Putting it Together 9 Oct 2007 | Page
  • 52. Putting it Together Filesystem Layout: 9 Oct 2007 | Page
  • 53. Putting it Together The Bootstrap file (index.php): Simplest: 9 Oct 2007 | Page
  • 54. Putting it Together Bootstrap klasė (Bootsrap.php) 9 Oct 2007 | Page
  • 55. Putting it Together Hello World! IndexController: 9 Oct 2007 | Page
  • 56. Putting it Together Hello World! ErrorController: 9 Oct 2007 | Page
  • 57. Putting it Together Hello World! View scripts: 9 Oct 2007 | Page
  • 58. Thank you! More on Zend Framework: http://framework.zend.com