SlideShare a Scribd company logo
1 of 55
ZEND FRAMEWORK: GETTING
        TO GRIPS
         Ryan Mauger
WHO IS RYAN MAUGER?
• Zend   Framework Contributor

• Zend   Framework CR Team Member

• Co-Author     of Zend Framework 2 in Action (With Rob Allen)

• Technical   Editor for Zend Framework: A Beginners Guide

• Community     Supporter

• Zend   Certified PHP5 Engineer

• Lead   Developer at Lupimedia
WHAT ARE YOU GOING TO
       TAKE AWAY

Fundamental concepts to help you figure things out
                 for yourself
WHERE TO START?

• Tutorials

  • Akrabat’s    (Rob Allen): http://akrabat.com/zft

  • Official   Quickstart: http://bit.ly/zf-quickstart

• Build   your own sandbox

  • KEEP   IT!

  • Add    to it, keep additions for later reference
WHATS NEXT?

• Dispatch   cycle

• Autoloaders, Plugin   Loaders & Resource Loaders

• Plugins

• Helpers

• Models

• Forms, Decorators, Validators   & Filters
BUT WHAT SHOULD I
   TACKLE FIRST?
BUT WHAT SHOULD I
   TACKLE FIRST?

• Understand   the Lifecycle of a ZF request
BUT WHAT SHOULD I
   TACKLE FIRST?

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request
BUT WHAT SHOULD I
   TACKLE FIRST?

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request
BUT WHAT SHOULD I
   TACKLE FIRST?

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request

• Understand   the Lifecycle of a ZF request
EXECUTION LIFECYCLE
       Bootstrap

        Route

       Dispatch

       Simple?
HOW ABOUT A FLOWCHART?




Source: Polly Wong http://www.slideshare.net/polleywong/zend-framework-dispatch-workflow
YIKES!
SOMETHING SIMPLER
           Bootstrap


         routeStartup

             route

        routeShutdown


      dispatchLoopStartup


          preDispatch


        dispatch (action)


         postDispatch


     dispatchLoopShutdown
SOMETHING SIMPLER
   FC Plugin
    routeStartup
                         Router
                            route


   routeShutdown

 dispatchLoopStartup
                       Controller
    preDispatch          preDispatch




                                           Dispatch Loop
                       dispatch (action)


    postDispatch        postDispatch

dispatchLoopShutdown
BOOTSTRAPPING
BOOTSTRAPPING
• Initialise   everything you may need
• Make things ready for your request to be
 dispatched
• Do   nothing module specific
• Remember        your module bootstraps, even if they
 are empty!
MODULE BOOTSTRAPS
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.controllerDirectory.default = APPLICATION_PATH "/controllers"
resources.modules[] = ""



            <?php

            class Abcd_Bootstrap extends Zend_Application_Module_Bootstrap
            {
                protected function _initRest()
                {
                    $fc = Zend_Controller_Front::getInstance();
                     $restRoute = new Zend_Rest_Route($fc, array(), array(
                        'abcd' => array('contacts'),
                    ));
                    $fc->getRouter()->addRoute('contacts', $restRoute);
                }
            }
FRONT CONTROLLER
PLUGINS AND ACTION
      HELPERS
FRONT CONTROLLER
                 PLUGINS
• Provide    hooks into various points in the request lifecycle

• Run Automatically

• Should     be able to run independently of the action controller
 itself

• Exceptionsthrown in preDispatch will not prevent further
 plugins preDispatch calls being run

• Are     easier to use if you have no constructor parameters.
ADDING A FRONT
                CONTROLLER PLUGIN
• In the config
  autoloaderNamespaces[] = " My_ "
  resources.frontController.plugins[] = "My_Controller_Plugin";

• In   the bootstrap (useful for modules)
        <?php

        class ModuleName_Bootstrap extends Zend_Application_Module_Bootstrap
        {
        	 protected function _initPlugins()
        	 {
        	 	 $this->getApplication()
        	 	        ->getResourcePlugin('frontController')
        	 	        ->registerPlugin(new ModuleName_Plugin_Acl());
        	 }
        }
ACTION HELPERS

• Provide   hooks into the request lifecycle

• Run   automatically, or on demand

• Are intended to either replace repeated code in your actions
 (think DRY) or to extend functionality of action controllers

• Thrown Exceptions in pre/postDispatch will stop further
 execution of other action helpers
ADDING AN ACTION HELPER
• In   the config
 resources.frontController.actionHelperPaths.My_Action_Helper = "My/Action/Helper"



• In   the bootstrap (useful for modules)
       <?php

       class Abcd_Bootstrap extends Zend_Application_Module_Bootstrap
       {
           protected function _initActionHelpers()
           {
           	 Zend_Controller_Action_HelperBroker::addPath(
           	      'My/Action/Helper',
           	      'My_Action_Helper'
           	 );
           	
           	 Zend_Controller_Action_HelperBroker::addHelper(
           	      new My_Action_Helper_Thingy()
           	 );
           }
       }
ACTION HELPER OR FC
              PLUGIN?
                                   START
Front Controller Plugin                                          Action Helper

                                   Do you need to
Error Handler                   interact with it from
                                   the controller?      Yes     Redirector
      Layout                                                  Flash Messenger
                                            No
  Action stack                                                Context Switch
                                   Do you need to

                          Yes
                                  hook earlier than
                                    preDispatch?        No
                                                              View Renderer
AUTOLOADING
AUTOLOADING

  Autoloading
AUTOLOADING

  Autoloading

 Plugin loading
AUTOLOADING

   Autoloading

  Plugin loading

 Resource loading
AUTOLOADING
• Library   components
• Follows   PEAR naming
• Used   where ever you see:
 • new   Zend_Form()

 • new   Zend_Db()

 • new   Zend_Service_...
PLUGIN LOADING
• Prefixes   names to resolve a classname, and path
 to load
• Can   work away from the include_path
• Is
   used wherever a class is created with only a
 suffix
• FormElements, View Helpers, Action Helpers,
 Resource plugins
RESOURCE LOADING
• Resolves  classnames which do not map 1:1 with the
  filesystem
  Application_Model_Page : application/models/Page.php
• Is   used for module components (forms, models, services)
• Provide   a namespace for the module
• Iscreated automatically for modules with a module
  bootstrap
• Makes your modules directories ‘tidier’ (controllers, views,
  models, forms, etc)
LOADERS IN ACTION
                            Plugin Loading
 <?php

 class My_Form extends Zend_Form
 {
 	 public function init()
 	 {
 	 	 $this->addElement('Text', 'aTextBox', array('label' => 'A text Box'));
 	 }
 }



“Text” is resolved to Zend_Form_Element_Text by looping
   through the given prefix paths until a match is found
LOADERS IN ACTION
                    Adding your own prefix path
   <?php

   class My_Form extends Zend_Form
   {
   	 public function init()
   	 {
   	 	 $this->addElementPrefixPath('My_Form_Element_', 'My/Form/Elements/');
   	 	 $this->addElement('Text', 'aTextBox', array('label' => 'A text Box'));
   	 }
   }


  Zend_Form::addElementPrefixPath() is an example of accessing a
             resource loader to add an extra prefix path.
There is also an optional third parameter, to specifically supply a path
          for only elements, decorators, filters, or validators
LOADERS IN ACTION
                      Autoloading
  [production]
  phpSettings.display_startup_errors = 0
  phpSettings.display_errors = 0
  autoloaderNamespaces[] = "My_"
  includePaths.library = APPLICATION_PATH "/../library"
  bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
  bootstrap.class = "Bootstrap"


<?php

class IndexController extends Zend_Controller_Action
{
	 public function indexAction()
	 {
	 	 $myComponent = new My_Cool_Component();
	 }
}
LOADERS IN ACTION
                           Resource Loading

<?php

class Admin_IndexController extends
                  Zend_Controller_Action
{
	 public function indexAction()
	 {
	 	 $form = new Admin_Form_EditPage();
	 	 $this->view->form = $form;
	 }
}
CONSTRUCTOR OPTIONS
    What can I put in $options?
WHAT CAN I PUT IN
                 $OPTIONS?
•   $options is always an associative array

•   Each key is normalised and turned into a method name for a setter.
    ‘foo’ becomes ‘setFoo’, ‘bar’ becomes ‘setBar’

•   If that setter exists, it is called, and the value at that index is passed as
    a single argument

•   Generally, exceptions are not thrown for invalid options.

•   Some components will store any options without a setter for other
    purposes, e.g. Zend_Form, options without a setter become attributes
WHERE CAN I SEE THE
          AVAILABLE SETTERS?

• The API   documentation (http://framework.zend.com/apidoc/
 core)

• Your   IDE (autocomplete)

• The    manual
ADVANTAGES OF USING
         OPTIONS ARRAYS


• Flexibility   of configuration

• Easily   extended

• Largely   self documenting
TAKING ADVANTAGE OF THE
 OPTIONS ARRAY IN ZEND_FORM
<?php
                                                                   setPage() is called
class Admin_Form_EditPage extends Zend_Form
{
	   protected $_page;
                                                                 before init(), allowing
	
	   public function init()
                                                               you to pass through the
	
	
    {
    	   $this->addElements(array(                               constructor an object,
	   	       //...
	
	
    	
    	   	
            $multi = new Zend_Form_Element_Select('multi'),
            //...
                                                                array, or scalar value to
	
	
    	
    	
        ));                                                         be used for any
	
	
    	
    }
        $multi->setMultiOptions($this->_page->getOptions());
                                                                     purpose when
	
	   public function setPage(Application_Model_Page $page)        initialising your form.
	   {
	   	   $this->_page = $page;
	   	   return $this;
	   }
}
DECORATORS
HOW THE HECK DO
DECORATORS WORK THEN?
Label <dt><label></label></dt>      Rendered
                                   inside-out,
    HtmlTag <dd>...</dd>              each
                                    wrapping,
                                  appending or
      Element <input.../>
                                   prepending
    Description <p>...</p>       content to the
                                  content from
     Errors <ul>...</ul>          the previous
                                   decorator
DEFINING A DECORATOR
        STACK
	    	   $multi->setMultiOptions($this->_page->getOptions())
	    	         ->setDecorators(array(
	    	             'ViewHelper',
	    	             'Description',
	    	             'Errors',
	    	             array('HtmlTag', array('tag' => 'dd')),
	    	             array('Label',   array('tag' => 'dt')),
	    	         ));

       ViewHelper - Renders the element
    Description - renders a paragraph beneath
       the element (if a description is set)
     Errors - Adds a ul beneath the element
       HtmlTag - Renders the dd element
      Label - Renders the label and dt tags
DEFINING A DECORATOR
        STACK
       BeachPHP Demo
THE M IN YOUR MVC
MODELLING DATA

• Business   logic

• Domain     logic

• Services

• Mappers

• Entities

• Models
Application
Front Controller   Domain logic   RDBMS


   Action
  Controller




     View
Zend_Db_Table based models
                        DIRECT TDG


 Domain?




                          RDBMS
Zend_Db_Table
Zend_Db_Table based models
                                 TDG WRAPPER BASED

         Domain                  MODEL




                                RDBMS
Entity         Zend_Db_Table
DataMapper based models
                               QUICKSTART MAPPER

         Domain

             Mapper


                               RDBMS
Entity
             Zend_Db_Table
DataMapper based models
                                   DOCTRINE2



     Domain


                                    DBAL




Entity        Mapper


                                   RDBMS
WHICH PATTERN TO USE?

• Maintenance   cycle
• Complexity   of the application
• Project   timeframe
• Available
        solutions (Doctrine, Propel,
 phpDataMapper), do they suit you?
WHAT DOES ZF SUPPORT?
       DB Abstraction
WHAT DOES ZF SUPPORT?
                     DB Abstraction

Expect some sort of integration with Doctrine2 when ZF2
                         arrives
Doctrine2 is gaining popularity as the ORM of choice for ZF
                       on the whole
  Doctrine 1.x is already a very common choice of ORM,
             though based on Active Record
THANKS FOR LISTENING


       Questions?

More Related Content

What's hot

Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"Daniel Bryant
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenThorsten Kamann
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin developmentCaldera Labs
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyTesting Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyMatthew Beale
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cliCory Forsyth
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSShekhar Gulati
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.SWAAM Tech
 
Understanding
Understanding Understanding
Understanding Arun Gupta
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpdayStephan Hochdörfer
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Oscar Merida
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-startedtutorialsruby
 

What's hot (17)

slingmodels
slingmodelsslingmodels
slingmodels
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
J1 2015 "Debugging Java Apps in Containers: No Heavy Welding Gear Required"
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin development
 
Testing Ember Apps: Managing Dependency
Testing Ember Apps: Managing DependencyTesting Ember Apps: Managing Dependency
Testing Ember Apps: Managing Dependency
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Ember testing internals with ember cli
Ember testing internals with ember cliEmber testing internals with ember cli
Ember testing internals with ember cli
 
Developing Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJSDeveloping Modern Java Web Applications with Java EE 7 and AngularJS
Developing Modern Java Web Applications with Java EE 7 and AngularJS
 
Apache Ant
Apache AntApache Ant
Apache Ant
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
Understanding
Understanding Understanding
Understanding
 
Testing untestable code - phpday
Testing untestable code - phpdayTesting untestable code - phpday
Testing untestable code - phpday
 
Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)Staying Sane with Drupal (A Develper's Survival Guide)
Staying Sane with Drupal (A Develper's Survival Guide)
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-started
 

Similar to Webinar: Zend framework Getting to grips (ZF1)

Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Ryan Mauger
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentBrad Williams
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress PluginBrad Williams
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...WordCamp Sydney
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin developmentMostafa Soufi
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialJoe Ferguson
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Z-Ray: A customizable development tool belt (Zendcon 2016)
Z-Ray: A customizable development tool belt (Zendcon 2016)Z-Ray: A customizable development tool belt (Zendcon 2016)
Z-Ray: A customizable development tool belt (Zendcon 2016)Mathew Beane
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress developmentSteve Mortiboy
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Extending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and ReactExtending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and ReacteZ Systems
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_companyGanesh Kulkarni
 

Similar to Webinar: Zend framework Getting to grips (ZF1) (20)

Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)Zend framework: Getting to grips (ZF1)
Zend framework: Getting to grips (ZF1)
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
2007 Zend Con Mvc
2007 Zend Con Mvc2007 Zend Con Mvc
2007 Zend Con Mvc
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 TutorialAdventures in Laravel 5 SunshinePHP 2016 Tutorial
Adventures in Laravel 5 SunshinePHP 2016 Tutorial
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Z-Ray: A customizable development tool belt (Zendcon 2016)
Z-Ray: A customizable development tool belt (Zendcon 2016)Z-Ray: A customizable development tool belt (Zendcon 2016)
Z-Ray: A customizable development tool belt (Zendcon 2016)
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Extending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and ReactExtending eZ Platform v2 with Symfony and React
Extending eZ Platform v2 with Symfony and React
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 

Recently uploaded

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 Processorsdebabhi2
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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.pptxEarley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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 MenDelhi Call girls
 
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 textsMaria Levchenko
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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 MenDelhi Call girls
 

Recently uploaded (20)

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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 

Webinar: Zend framework Getting to grips (ZF1)

  • 1. ZEND FRAMEWORK: GETTING TO GRIPS Ryan Mauger
  • 2. WHO IS RYAN MAUGER? • Zend Framework Contributor • Zend Framework CR Team Member • Co-Author of Zend Framework 2 in Action (With Rob Allen) • Technical Editor for Zend Framework: A Beginners Guide • Community Supporter • Zend Certified PHP5 Engineer • Lead Developer at Lupimedia
  • 3. WHAT ARE YOU GOING TO TAKE AWAY Fundamental concepts to help you figure things out for yourself
  • 4. WHERE TO START? • Tutorials • Akrabat’s (Rob Allen): http://akrabat.com/zft • Official Quickstart: http://bit.ly/zf-quickstart • Build your own sandbox • KEEP IT! • Add to it, keep additions for later reference
  • 5. WHATS NEXT? • Dispatch cycle • Autoloaders, Plugin Loaders & Resource Loaders • Plugins • Helpers • Models • Forms, Decorators, Validators & Filters
  • 6. BUT WHAT SHOULD I TACKLE FIRST?
  • 7. BUT WHAT SHOULD I TACKLE FIRST? • Understand the Lifecycle of a ZF request
  • 8. BUT WHAT SHOULD I TACKLE FIRST? • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request
  • 9. BUT WHAT SHOULD I TACKLE FIRST? • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request
  • 10. BUT WHAT SHOULD I TACKLE FIRST? • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request • Understand the Lifecycle of a ZF request
  • 11. EXECUTION LIFECYCLE Bootstrap Route Dispatch Simple?
  • 12. HOW ABOUT A FLOWCHART? Source: Polly Wong http://www.slideshare.net/polleywong/zend-framework-dispatch-workflow
  • 14. SOMETHING SIMPLER Bootstrap routeStartup route routeShutdown dispatchLoopStartup preDispatch dispatch (action) postDispatch dispatchLoopShutdown
  • 15. SOMETHING SIMPLER FC Plugin routeStartup Router route routeShutdown dispatchLoopStartup Controller preDispatch preDispatch Dispatch Loop dispatch (action) postDispatch postDispatch dispatchLoopShutdown
  • 17. BOOTSTRAPPING • Initialise everything you may need • Make things ready for your request to be dispatched • Do nothing module specific • Remember your module bootstraps, even if they are empty!
  • 18. MODULE BOOTSTRAPS resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" resources.frontController.controllerDirectory.default = APPLICATION_PATH "/controllers" resources.modules[] = "" <?php class Abcd_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initRest() { $fc = Zend_Controller_Front::getInstance(); $restRoute = new Zend_Rest_Route($fc, array(), array( 'abcd' => array('contacts'), )); $fc->getRouter()->addRoute('contacts', $restRoute); } }
  • 20. FRONT CONTROLLER PLUGINS • Provide hooks into various points in the request lifecycle • Run Automatically • Should be able to run independently of the action controller itself • Exceptionsthrown in preDispatch will not prevent further plugins preDispatch calls being run • Are easier to use if you have no constructor parameters.
  • 21. ADDING A FRONT CONTROLLER PLUGIN • In the config autoloaderNamespaces[] = " My_ " resources.frontController.plugins[] = "My_Controller_Plugin"; • In the bootstrap (useful for modules) <?php class ModuleName_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initPlugins() { $this->getApplication() ->getResourcePlugin('frontController') ->registerPlugin(new ModuleName_Plugin_Acl()); } }
  • 22. ACTION HELPERS • Provide hooks into the request lifecycle • Run automatically, or on demand • Are intended to either replace repeated code in your actions (think DRY) or to extend functionality of action controllers • Thrown Exceptions in pre/postDispatch will stop further execution of other action helpers
  • 23. ADDING AN ACTION HELPER • In the config resources.frontController.actionHelperPaths.My_Action_Helper = "My/Action/Helper" • In the bootstrap (useful for modules) <?php class Abcd_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initActionHelpers() { Zend_Controller_Action_HelperBroker::addPath( 'My/Action/Helper', 'My_Action_Helper' ); Zend_Controller_Action_HelperBroker::addHelper( new My_Action_Helper_Thingy() ); } }
  • 24. ACTION HELPER OR FC PLUGIN? START Front Controller Plugin Action Helper Do you need to Error Handler interact with it from the controller? Yes Redirector Layout Flash Messenger No Action stack Context Switch Do you need to Yes hook earlier than preDispatch? No View Renderer
  • 27. AUTOLOADING Autoloading Plugin loading
  • 28. AUTOLOADING Autoloading Plugin loading Resource loading
  • 29. AUTOLOADING • Library components • Follows PEAR naming • Used where ever you see: • new Zend_Form() • new Zend_Db() • new Zend_Service_...
  • 30. PLUGIN LOADING • Prefixes names to resolve a classname, and path to load • Can work away from the include_path • Is used wherever a class is created with only a suffix • FormElements, View Helpers, Action Helpers, Resource plugins
  • 31. RESOURCE LOADING • Resolves classnames which do not map 1:1 with the filesystem Application_Model_Page : application/models/Page.php • Is used for module components (forms, models, services) • Provide a namespace for the module • Iscreated automatically for modules with a module bootstrap • Makes your modules directories ‘tidier’ (controllers, views, models, forms, etc)
  • 32. LOADERS IN ACTION Plugin Loading <?php class My_Form extends Zend_Form { public function init() { $this->addElement('Text', 'aTextBox', array('label' => 'A text Box')); } } “Text” is resolved to Zend_Form_Element_Text by looping through the given prefix paths until a match is found
  • 33. LOADERS IN ACTION Adding your own prefix path <?php class My_Form extends Zend_Form { public function init() { $this->addElementPrefixPath('My_Form_Element_', 'My/Form/Elements/'); $this->addElement('Text', 'aTextBox', array('label' => 'A text Box')); } } Zend_Form::addElementPrefixPath() is an example of accessing a resource loader to add an extra prefix path. There is also an optional third parameter, to specifically supply a path for only elements, decorators, filters, or validators
  • 34. LOADERS IN ACTION Autoloading [production] phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 autoloaderNamespaces[] = "My_" includePaths.library = APPLICATION_PATH "/../library" bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" <?php class IndexController extends Zend_Controller_Action { public function indexAction() { $myComponent = new My_Cool_Component(); } }
  • 35. LOADERS IN ACTION Resource Loading <?php class Admin_IndexController extends Zend_Controller_Action { public function indexAction() { $form = new Admin_Form_EditPage(); $this->view->form = $form; } }
  • 36. CONSTRUCTOR OPTIONS What can I put in $options?
  • 37. WHAT CAN I PUT IN $OPTIONS? • $options is always an associative array • Each key is normalised and turned into a method name for a setter. ‘foo’ becomes ‘setFoo’, ‘bar’ becomes ‘setBar’ • If that setter exists, it is called, and the value at that index is passed as a single argument • Generally, exceptions are not thrown for invalid options. • Some components will store any options without a setter for other purposes, e.g. Zend_Form, options without a setter become attributes
  • 38. WHERE CAN I SEE THE AVAILABLE SETTERS? • The API documentation (http://framework.zend.com/apidoc/ core) • Your IDE (autocomplete) • The manual
  • 39. ADVANTAGES OF USING OPTIONS ARRAYS • Flexibility of configuration • Easily extended • Largely self documenting
  • 40. TAKING ADVANTAGE OF THE OPTIONS ARRAY IN ZEND_FORM <?php setPage() is called class Admin_Form_EditPage extends Zend_Form { protected $_page; before init(), allowing public function init() you to pass through the { $this->addElements(array( constructor an object, //... $multi = new Zend_Form_Element_Select('multi'), //... array, or scalar value to )); be used for any } $multi->setMultiOptions($this->_page->getOptions()); purpose when public function setPage(Application_Model_Page $page) initialising your form. { $this->_page = $page; return $this; } }
  • 42. HOW THE HECK DO DECORATORS WORK THEN? Label <dt><label></label></dt> Rendered inside-out, HtmlTag <dd>...</dd> each wrapping, appending or Element <input.../> prepending Description <p>...</p> content to the content from Errors <ul>...</ul> the previous decorator
  • 43. DEFINING A DECORATOR STACK $multi->setMultiOptions($this->_page->getOptions()) ->setDecorators(array( 'ViewHelper', 'Description', 'Errors', array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), )); ViewHelper - Renders the element Description - renders a paragraph beneath the element (if a description is set) Errors - Adds a ul beneath the element HtmlTag - Renders the dd element Label - Renders the label and dt tags
  • 44. DEFINING A DECORATOR STACK BeachPHP Demo
  • 45. THE M IN YOUR MVC
  • 46. MODELLING DATA • Business logic • Domain logic • Services • Mappers • Entities • Models
  • 47. Application Front Controller Domain logic RDBMS Action Controller View
  • 48. Zend_Db_Table based models DIRECT TDG Domain? RDBMS Zend_Db_Table
  • 49. Zend_Db_Table based models TDG WRAPPER BASED Domain MODEL RDBMS Entity Zend_Db_Table
  • 50. DataMapper based models QUICKSTART MAPPER Domain Mapper RDBMS Entity Zend_Db_Table
  • 51. DataMapper based models DOCTRINE2 Domain DBAL Entity Mapper RDBMS
  • 52. WHICH PATTERN TO USE? • Maintenance cycle • Complexity of the application • Project timeframe • Available solutions (Doctrine, Propel, phpDataMapper), do they suit you?
  • 53. WHAT DOES ZF SUPPORT? DB Abstraction
  • 54. WHAT DOES ZF SUPPORT? DB Abstraction Expect some sort of integration with Doctrine2 when ZF2 arrives Doctrine2 is gaining popularity as the ORM of choice for ZF on the whole Doctrine 1.x is already a very common choice of ORM, though based on Active Record
  • 55. THANKS FOR LISTENING Questions?

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n