SlideShare a Scribd company logo
1 of 122
Download to read offline
Just married: Zend
        Framework and Doctrine
                              Benjamin Eberlei
                                direkt effekt GmbH

                              IPC Spring 2010


Eberlei (direkt effekt GmbH)      ZF and Doctrine 1   IPC Spring 2010   1 / 55
About Me

          Benjamin Eberlei
          direkt effekt GmBH
          (digital marketing)
          Open Source contributor
          (Zend Framework and Doctrine)
          Twitter @beberlei
          Blog: www.whitewashing.de
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   2 / 55
And You?




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   3 / 55
Model vs Persistence


                       Model
                         =
                      Your code
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   4 / 55
Model vs Persistence


           Persistence
                =
        Framework Code
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   5 / 55
Model vs Persistence


          Model = Your code
          Persistence = Framework Code
          You can implement the same
          business logic using any persistence
          solution out there!



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   6 / 55
Zend Framework Persistence

          Zend Db - Abstraction Layer




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   7 / 55
Zend Framework Persistence

          Zend Db - Abstraction Layer
          Zend Db Select - SQL Query Object




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   7 / 55
Zend Framework Persistence

          Zend Db - Abstraction Layer
          Zend Db Select - SQL Query Object
          Zend Db Table - Table/Row Data
          Gateway pattern



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   7 / 55
Zend Framework Persistence

          Zend Db - Abstraction Layer
          Zend Db Select - SQL Query Object
          Zend Db Table - Table/Row Data
          Gateway pattern
    No Object-Relational Mapping Support!


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   7 / 55
Doctrine 1


          Object-Relational Mapping, Active Record




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   8 / 55
Doctrine 1


          Object-Relational Mapping, Active Record
          Doctrine Query Language




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   8 / 55
Doctrine 1


          Object-Relational Mapping, Active Record
          Doctrine Query Language
          Hydrators




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   8 / 55
Doctrine 1


          Object-Relational Mapping, Active Record
          Doctrine Query Language
          Hydrators
          Database Migrations



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   8 / 55
Doctrine Modelling Workflow

    1. Setup Doctrine Bootstrap




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
Doctrine Modelling Workflow

    1. Setup Doctrine Bootstrap
    2. Define a YAML Schema




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
Doctrine Modelling Workflow

    1. Setup Doctrine Bootstrap
    2. Define a YAML Schema
    3. Generate Model and Table PHP classes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
Doctrine Modelling Workflow

    1.    Setup Doctrine Bootstrap
    2.    Define a YAML Schema
    3.    Generate Model and Table PHP classes
    4.    Generate Database Schema from Models




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
Doctrine Modelling Workflow

    1.    Setup Doctrine Bootstrap
    2.    Define a YAML Schema
    3.    Generate Model and Table PHP classes
    4.    Generate Database Schema from Models
    5.    Repeat (2)-(4) for Iterations of your models.




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
Doctrine Modelling Workflow

    1.    Setup Doctrine Bootstrap
    2.    Define a YAML Schema
    3.    Generate Model and Table PHP classes
    4.    Generate Database Schema from Models
    5.    Repeat (2)-(4) for Iterations of your models.
    6.    In production, use migrations for schema
          evolvement.

Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   9 / 55
A Doctrine Project Layout


          Non-PEAR Structure




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   10 / 55
A Doctrine Project Layout


          Non-PEAR Structure
          No Module Prefixes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   10 / 55
A Doctrine Project Layout


          Non-PEAR Structure
          No Module Prefixes
          Autoloading?




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   10 / 55
A Doctrine Project Layout


          Non-PEAR Structure
          No Module Prefixes
          Autoloading?
          Configurable (PEAR)..



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   10 / 55
A Doctrine Project Layout


          Non-PEAR Structure
          No Module Prefixes
          Autoloading?
          Configurable (PEAR)..
          ..Not enough for ZF!


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   10 / 55
Zend Framework Projects


          Model * in models/




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   11 / 55
Zend Framework Projects


          Model * in models/
          Single Module Project




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   11 / 55
Zend Framework Projects


          Model * in models/
          Single Module Project
          Not PEAR Standard




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   11 / 55
Zend Framework Projects


          Model * in models/
          Single Module Project
          Not PEAR Standard
          Special Autoloader



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   11 / 55
Modular ZF Project



          Each Module has models/




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   12 / 55
Modular ZF Project



          Each Module has models/
          Again Special Autoloader




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   12 / 55
ZF + Doctrine Integration
          Not a ZF Component




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation
          Includes:
             1. Zend Application Resource




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation
          Includes:
             1. Zend Application Resource
             2. Zend Tool Integration




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation
          Includes:
             1. Zend Application Resource
             2. Zend Tool Integration
             3. Zend Forms from Doctrine Metadata


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation
          Includes:
             1.   Zend Application Resource
             2.   Zend Tool Integration
             3.   Zend Forms from Doctrine Metadata
             4.   Paginator Adapter

Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
ZF + Doctrine Integration
          Not a ZF Component
          Download:
          http://github.com/beberlei/zf-doctrine
          One Goal: No code-generation
          Includes:
             1.   Zend Application Resource
             2.   Zend Tool Integration
             3.   Zend Forms from Doctrine Metadata
             4.   Paginator Adapter
             5.   Model List View Helper
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   13 / 55
Zend Application Resource


  1. Install using Zend Tool:
  zf create project forum
  zf create-project doctrine –dsn=$DSN




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   14 / 55
Zend Application Resource
  2. Register manually with Zend Application
   resources . doctrine . connections . default . dsn = " "
   pluginpaths . Z F D o c t r i n e _ A p p l i c a t i o n _ R e s o u r c e
         = " ZFDoctrine / Application / Resource "
   a u toloade r n a m e s p a c e s [] = " Doctrine "
   a u toloade r n a m e s p a c e s [] = " ZFDoctrine


  .




Eberlei (direkt effekt GmbH)            ZF and Doctrine 1           IPC Spring 2010   15 / 55
Configuring the Application
Resource
  Configuring Connection DSN
   resources . doctrine . connections . < name >. dsn


  Configuring Connection Attributes
   resources . doctrine . connections . < name >. attributes


  Configuring Manager Attributes
   resources . doctrine . manager . attributes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1     IPC Spring 2010   16 / 55
ZFDoctrine Conventions
          Both ZF 1 and Doctrine 1 are magic boxes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   17 / 55
ZFDoctrine Conventions
          Both ZF 1 and Doctrine 1 are magic boxes
          Enforcing Conventions




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   17 / 55
ZFDoctrine Conventions
          Both ZF 1 and Doctrine 1 are magic boxes
          Enforcing Conventions
          Model Classes: $Module Model $Name:
             1.   Default Model User
             2.   Default Model Group
             3.   Forum Model Thread
             4.   Forum Model Board




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   17 / 55
ZFDoctrine Conventions
          Both ZF 1 and Doctrine 1 are magic boxes
          Enforcing Conventions
          Model Classes: $Module Model $Name:
             1.   Default Model User
             2.   Default Model Group
             3.   Forum Model Thread
             4.   Forum Model Board
          Define Metadata Attributes refClass, local,
          model and foreign explicitly
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   17 / 55
A Doctrine Project
  zf create project forum
  zf create-project doctrine –dsn

  Creating four essential Doctrine Directories:
          application/configs/schema
          application/configs/fixtures
          application/configs/migrations
          application/configs/sql
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   18 / 55
Example Yaml schema: Forum
  Put a forum.yml in the schema directory:
   F o rum_Mod e l _ C a t e g o r y :
       columns :
         name : string (50)
         description : string (99999)

   Forum_Mode l_Boar d :
     columns :
       category_id : integer (10)
       name : string (100)
       description : string (5000)
     relations :
       Category :
         class : F o r u m _ Model_Category
         local : category_id
         foreign : id
       Threads :
         class : Fo ru m_ Model_Thread
         local : id
         foreign : board_id


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   19 / 55
Generate Models from Yaml


  zf generate-models-from-yaml doctrine




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   20 / 55
Generate Models from Yaml


  zf generate-models-from-yaml doctrine

  Generate Table Classes (application.ini)
   resources . doctrine . generateModels . generateTableClasses =
       true




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   20 / 55
Generate Models




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   21 / 55
Generate Models




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   22 / 55
Generated Model Classes


          Records
          Base Records
          Tables




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   23 / 55
Code Generation?

          Doctrine creates Models from Yaml files.




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   24 / 55
Code Generation?

          Doctrine creates Models from Yaml files.
          ...optionally(!)




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   24 / 55
Code Generation?

          Doctrine creates Models from Yaml files.
          ...optionally(!)
          You can skip Yaml and directly code the
          Model (Records and Tables)




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   24 / 55
Code Generation?

          Doctrine creates Models from Yaml files.
          ...optionally(!)
          You can skip Yaml and directly code the
          Model (Records and Tables)
          Zend Framework Project Support works
          without Yaml.


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   24 / 55
Generated Record:
   class For u m _ M o de l _ C ategory extends
       Forum_Model_Base_Category
   {
   }


  Generated Table:
   class F o r u m _ M o d e l _ C a t e g o r y T a b le extends Doctrine_Table
   {
       public static function getInstance ()
       {
             return Doctrine_Core :: getTable (
                     ’ F o r u m _ Model_Category ’) ;
       }
   }


  Generated Base Record:

Eberlei (direkt effekt GmbH)        ZF and Doctrine 1        IPC Spring 2010        25 / 55
abstract class F o r u m _ M o d e l _ B a s e _ C a t e g o r y extends
       Doctrine_Record
   {
       public function setTableDefinition ()
       {
           $this - > setTableName ( ’ forum_categories ’) ;
           $this - > hasColumn ( ’ name ’ , ’ string ’ , 50 , array (
                 ’ type ’ = > ’ string ’ ,
                 ’ length ’ = > ’ 50 ’ ,
                 ));
           $this - > hasColumn ( ’ description ’ , ’ string ’ , 99999 ,
               array (
                 ’ type ’ = > ’ string ’ ,
                 ’ length ’ = > ’ 99999 ’ ,
                 ));
       }

        public function setUp ()
        {
            parent :: setUp () ;
            $this - > hasMany ( ’ Forum_Model_Board ’ , array (
                  ’ local ’ = > ’ id ’ ,
                  ’ foreign ’ = > ’ category_id ’) ) ;
        }
   }


Eberlei (direkt effekt GmbH)     ZF and Doctrine 1      IPC Spring 2010   26 / 55
Generating Database


  zf build-project doctrine –reload
          Drop and Create Database
          Create Tables
          Load Fixtures



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   27 / 55
Migrations


  Update your Database Schema:
          zf show-migration doctrine




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   28 / 55
Migrations


  Update your Database Schema:
          zf show-migration doctrine
          zf generate-migration doctrine




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   28 / 55
Migrations


  Update your Database Schema:
          zf show-migration doctrine
          zf generate-migration doctrine
          zf execute-migration doctrine




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   28 / 55
Forms for Doctrine Models


          Using Doctrine Metadata for other, non
          ORM purposes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   29 / 55
Forms for Doctrine Models


          Using Doctrine Metadata for other, non
          ORM purposes
          Configuration of Zend Form instances




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   29 / 55
Forms for Doctrine Models


          Using Doctrine Metadata for other, non
          ORM purposes
          Configuration of Zend Form instances
          Mostly for backend (scaffolding) purposes




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   29 / 55
A Simple Form


   $form = new Z F D o c t r i ne_Fr om_M odel ( array (
       ’ model ’ = > ’ F o r um_Model_Category ’ ,
       ’ action ’ = > ’. ’ ,
       ’ method ’ = > ’ post ’
   ));




Eberlei (direkt effekt GmbH)      ZF and Doctrine 1         IPC Spring 2010   30 / 55
A Simple Form: Tweaking

   $form = new Z F D o c t r i ne_Fo rm_M odel ( array (
       ’ model ’ = > ’ F o r um_Model_Category ’ ,
       ’ method ’ = > ’ post ’ ,
       ’ action ’ = > $this - > _helper - > url (
            ’add - category ’ , ’ admin ’) ,
       ’ fieldLabels ’ = > array (
            ’ name ’ = > ’ Name ’ ,
            ’ description ’ = > ’ Description ’ ,
       ),
       ’ fieldTypes ’ = > array (
            ’ description ’ = > ’ textarea ’ ,
       ),
   ));




Eberlei (direkt effekt GmbH)      ZF and Doctrine 1         IPC Spring 2010   31 / 55
A Simple Form: Tweaking




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   32 / 55
A Simple Form: Controller

   public function add CategoryAction ()
   {
       $form = $this - > createCategoryForm () ;
       $request = $this - > getRequest () ;
       $post = $request - > getPost () ;

        if ( $request - > isPost () && $form - > isValid ( $post ) ) {
             $form - > save () ;

              $this - > _helper - > redirector ( ’ success ’ , ’ admin ’) ;
        }

        $this - > view - > form = $form ;
   }




Eberlei (direkt effekt GmbH)      ZF and Doctrine 1      IPC Spring 2010   33 / 55
A Simple Form: Updating
   public function e di tCategoryAction ()
   {
       $categoryId = $this - > _getParam ( ’ id ’) ;

        $form = $this - > createCategoryForm () ;
        $request = $this - > getRequest () ;
        $post = $request - > getPost () ;

        $table = Doctrine :: getTable ( ’ Forum_Model_Category ’) ;
        $category = $table - > find ( $categoryId ) ;
        $form - > setRecord ( $category ) ;

        if ( $request - > isPost () && $form - > isValid ( $post ) ) {
             $form - > save () ;

              $this - > _helper - > redirector ( ’ success ’ , ’ admin ’) ;
        }

        $this - > view - > form = $form ;
   }



Eberlei (direkt effekt GmbH)      ZF and Doctrine 1      IPC Spring 2010   34 / 55
A Simple Form: Action Helper

   public function add CategoryAction ()
   {
       $form = $this - > createCategoryForm () ;
       $this - > _helper - > modelForm ( $form , ’ success ’) ;
   }

   public function e di tCategoryAction ()
   {
       $form = $this - > createCategoryForm () ;
       $this - > getHelper ( ’ modelForm ’)
             -> setRecordIdParam ( ’ id ’)
             -> handleForm ( $form , ’ success ’) ;
   }




Eberlei (direkt effekt GmbH)    ZF and Doctrine 1      IPC Spring 2010   35 / 55
Advanced Forms: Relations
  Relations rendered as (multi-)select fields:
   public function addBoardAction ()
   {
       $form = new Z F D o ctri ne_Fo rm_M odel ( array (
           ’ model ’ = > ’ Forum_Model_Board ’ ,
       ));
       $this - > _helper - > modelForm ( $form , " success " ) ;
   }




Eberlei (direkt effekt GmbH)     ZF and Doctrine 1     IPC Spring 2010   36 / 55
Advanced Forms: Relations
  Relations rendered as (multi-)select fields:
   public function addBoardAction ()
   {
       $form = new Z F D o ctri ne_Fo rm_M odel ( array (
           ’ model ’ = > ’ Forum_Model_Board ’ ,
       ));
       $this - > _helper - > modelForm ( $form , " success " ) ;
   }


  Control Option Labels:
   class For u m _ M o del _ C a tegory extends ...
   {
       public function __toString () {
           return $this - > id . " , " . $this - > name ;
       }
   }


Eberlei (direkt effekt GmbH)     ZF and Doctrine 1     IPC Spring 2010   36 / 55
Advanced Forms: Relations




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   37 / 55
Advanced Forms: Hooks

          Add Validators and Filters




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   38 / 55
Advanced Forms: Hooks

          Add Validators and Filters
          Change Decorators




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   38 / 55
Advanced Forms: Hooks

          Add Validators and Filters
          Change Decorators
          Use jQuery or Dojo Integration




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   38 / 55
Advanced Forms: Hooks

          Add Validators and Filters
          Change Decorators
          Use jQuery or Dojo Integration
          Hook methods: preGenerate() and
          postGenerate()



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   38 / 55
Advanced Forms: Hooks
  Adding decorators in preGenerate():
   class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del
   {
       protected function _preGenerate ()
       {
           // called before the form is generated
           $decorators = array (
               ’ FormElements ’ ,
               array ( array ( ’ data ’= > ’ HtmlTag ’) , array ( ’ tag ’= > ’
                    table ’) ) ,
               ’ Form ’
           );

              $this - > setDecorators ( $decorators ) ;
        }
   }




Eberlei (direkt effekt GmbH)      ZF and Doctrine 1       IPC Spring 2010    39 / 55
Advanced Forms: Hooks

  jQuery or Dojo Enable a Form:
   class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del
   {
       protected function _preGenerate ()
       {
           ZendX_JQuery :: enableForm ( $this ) ;
           // Zend_Dojo :: enableForm ( $this ) ;
       }
   }




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   40 / 55
Advanced Forms: Hooks

  Adding a validator in postGenerate():
   class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del
   {
       protected function _postGenerate ()
       {
           // called after the form is generated
           $validator = new Z e n d _ V a l i d a t e _ S t r i n g L e n g t h (
                array ( ’ min ’ = > 5 , ’ max ’ = > 255)
           );
           $this - > getElement ( ’ title ’)
                 -> addValidator ( $validator ) ;
       }
   }




Eberlei (direkt effekt GmbH)         ZF and Doctrine 1         IPC Spring 2010       41 / 55
Paginator Adapter

  Paginate a Doctrine Query:
   $query = Doctrine_Query :: create () ; // $query ...
   $adapter =
     new Z F D o c t r i n e _ P a g i n a t o r _ A d a p t e r _ D o c t r i n e Q u e r y ( $query ) ;
   $paginator = new Zend_Paginator ( $adapter ) ;




Eberlei (direkt effekt GmbH)                ZF and Doctrine 1               IPC Spring 2010           42 / 55
Paginator Adapter

  Paginate a Doctrine Query:
   $query = Doctrine_Query :: create () ; // $query ...
   $adapter =
     new Z F D o c t r i n e _ P a g i n a t o r _ A d a p t e r _ D o c t r i n e Q u e r y ( $query ) ;
   $paginator = new Zend_Paginator ( $adapter ) ;


  Paginate a Doctrine Table:
   $table = Doctrine_Core :: getTable ( ’ MyModel ’) ;
   $query = $table - > createQuery () ;




Eberlei (direkt effekt GmbH)                ZF and Doctrine 1               IPC Spring 2010           42 / 55
Model List View Helper


          Creates a paginated list for a model




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   43 / 55
Model List View Helper


          Creates a paginated list for a model
          Links to CRUD actions




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   43 / 55
Model List View Helper


          Creates a paginated list for a model
          Links to CRUD actions
          Reasonable default Look & Feel




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   43 / 55
Model List View Helper


          Creates a paginated list for a model
          Links to CRUD actions
          Reasonable default Look & Feel
          But offers full customization



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   43 / 55
Model List View Helper
   <h1 > Boards </ h1 >

   <?= $this - > modelList ( ’ Forum_Model_Board ’) ; ? >




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1    IPC Spring 2010   44 / 55
Model List View Helper
   <h1 > Boards </ h1 >

   <?= $this - > modelList ( ’ Forum_Model_Board ’) ; ? >


   <h1 > Boards </ h1 >
   <?= $this - > modelList ( ’ Forum_Model_Board ’ , array (
         ’ editRecordAction ’ = > ’ edit - board ’ ,
         ’ addRecordAction ’ = > ’add - board ’ ,
         ’ fieldLabels ’ = > array (
              ’ id ’ = > ’ ID ’ ,
              ’ category_id ’ = > ’ Category ’ ,
              ’ name ’ = > ’ Name ’ ,
              ’ description ’ = > ’ Description ’ ,
         )
   )); ?>




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1    IPC Spring 2010   44 / 55
Model List View Helper




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   45 / 55
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   46 / 55
Questions?




Eberlei (direkt effekt GmbH)     ZF and Doctrine 1   IPC Spring 2010   47 / 55
Zend Framework 2.0

          Currently Conversion to Namespaces




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   48 / 55
Zend Framework 2.0

          Currently Conversion to Namespaces
          Specified Goals:
             1. Ease the learning curve
             2. Make extending the framework trivially
                simple
             3. Simplify
             4. Favor the explicit over the magical




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   48 / 55
Zend Framework 2.0

          Currently Conversion to Namespaces
          Specified Goals:
             1. Ease the learning curve
             2. Make extending the framework trivially
                simple
             3. Simplify
             4. Favor the explicit over the magical
          ETA Q4/2010 or Q1/2011


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   48 / 55
Doctrine 2

          Separation of DBAL and ORM




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design
          DataMapper instead of ActiveRecord




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design
          DataMapper instead of ActiveRecord
          Powerful Metadata Mapping




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design
          DataMapper instead of ActiveRecord
          Powerful Metadata Mapping
          Considerable Performance Improvements




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design
          DataMapper instead of ActiveRecord
          Powerful Metadata Mapping
          Considerable Performance Improvements
          Currently Beta 1, Release on September 1st


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Doctrine 2

          Separation of DBAL and ORM
          Less Magic, More Explicit Design
          DataMapper instead of ActiveRecord
          Powerful Metadata Mapping
          Considerable Performance Improvements
          Currently Beta 1, Release on September 1st
          First class citizen in Symfony 2

Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   49 / 55
Wednesday, 8:30, Room Salon 1
      Guilherme on Doctrine 2!




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   50 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)
          Currently Support for MySql, PgSql,
          Oracle, Sqlite, IBM and PDO Db2




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)
          Currently Support for MySql, PgSql,
          Oracle, Sqlite, IBM and PDO Db2
          SqlSrv (+PDO) under development




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)
          Currently Support for MySql, PgSql,
          Oracle, Sqlite, IBM and PDO Db2
          SqlSrv (+PDO) under development
          Lots of Convenience Methods (Zend Db)




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)
          Currently Support for MySql, PgSql,
          Oracle, Sqlite, IBM and PDO Db2
          SqlSrv (+PDO) under development
          Lots of Convenience Methods (Zend Db)
          Currently planned: A Query Object
          (Zend Db Select, ezcDatabaseQuery)


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL
          PDO API (ezcDatabase)
          Currently Support for MySql, PgSql,
          Oracle, Sqlite, IBM and PDO Db2
          SqlSrv (+PDO) under development
          Lots of Convenience Methods (Zend Db)
          Currently planned: A Query Object
          (Zend Db Select, ezcDatabaseQuery)
          SQL DDL and Data-QL abstraction (PEAR
          MDB2 and ezcDatabaseSchema)
Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   51 / 55
Doctrine 2 DBAL Schema

          An OO-Approach to Database Schema




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   52 / 55
Doctrine 2 DBAL Schema

          An OO-Approach to Database Schema
          Vendor independent abstraction of Tables,
          Indexes, ForeignKeys and Sequences




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   52 / 55
Doctrine 2 DBAL Schema

          An OO-Approach to Database Schema
          Vendor independent abstraction of Tables,
          Indexes, ForeignKeys and Sequences
          Get required set-up or tear-down SQL




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   52 / 55
Doctrine 2 DBAL Schema

          An OO-Approach to Database Schema
          Vendor independent abstraction of Tables,
          Indexes, ForeignKeys and Sequences
          Get required set-up or tear-down SQL
          Get SQL to move from one to another
          schema



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   52 / 55
Doctrine 2 DBAL Schema

          An OO-Approach to Database Schema
          Vendor independent abstraction of Tables,
          Indexes, ForeignKeys and Sequences
          Get required set-up or tear-down SQL
          Get SQL to move from one to another
          schema
          Doctrine Migrations

Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   52 / 55
ZF 2 with Doctrine DBAL 2

          First class support?




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   53 / 55
ZF 2 with Doctrine DBAL 2

          First class support?
          Doctrine 2 DBAL API compatible with
          Zend Db?




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   53 / 55
ZF 2 with Doctrine DBAL 2

          First class support?
          Doctrine 2 DBAL API compatible with
          Zend Db?
          Zend Db Select drop-in replacement?




Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   53 / 55
ZF 2 with Doctrine DBAL 2

          First class support?
          Doctrine 2 DBAL API compatible with
          Zend Db?
          Zend Db Select drop-in replacement?
          Table-, Row-Data-Gateway?



Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   53 / 55
ZF 2 with Doctrine DBAL 2

          First class support?
          Doctrine 2 DBAL API compatible with
          Zend Db?
          Zend Db Select drop-in replacement?
          Table-, Row-Data-Gateway?
          ORM Integration?


Eberlei (direkt effekt GmbH)   ZF and Doctrine 1   IPC Spring 2010   53 / 55
Questions?




Eberlei (direkt effekt GmbH)     ZF and Doctrine 1   IPC Spring 2010   54 / 55
Thank You!
                Please rate this talk on joind.in:
                     http://joind.in/1710
                    Twitter: @beberlei Blog:
                 http://www.whitewashing.de



Eberlei (direkt effekt GmbH)     ZF and Doctrine 1   IPC Spring 2010   55 / 55

More Related Content

Similar to ZF and Doctrine Integration: A Deep Dive

LoneStarPHP Symfony2, Its Play Time
LoneStarPHP Symfony2, Its Play TimeLoneStarPHP Symfony2, Its Play Time
LoneStarPHP Symfony2, Its Play Timegeoffreytran
 
An introduction to the Spring Framework
An introduction to the Spring FrameworkAn introduction to the Spring Framework
An introduction to the Spring Frameworkweili_at_slideshare
 
BoxGrinder – FUDCon 2011 Tempe
BoxGrinder – FUDCon 2011 TempeBoxGrinder – FUDCon 2011 Tempe
BoxGrinder – FUDCon 2011 Tempemarekgoldmann
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelukdpe
 
BoxGrinder – FOSDEM 2012
BoxGrinder – FOSDEM 2012BoxGrinder – FOSDEM 2012
BoxGrinder – FOSDEM 2012marekgoldmann
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target PlatformsMickael Istria
 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend FrameworkStefan Koopmanschap
 
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...bethtib
 
.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16aminmesbahi
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonJeremy Brown
 
From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iAlan Seiden
 
Building Eclipse Plugins and RCP applications with Tycho
Building Eclipse Plugins and RCP applications with TychoBuilding Eclipse Plugins and RCP applications with Tycho
Building Eclipse Plugins and RCP applications with Tychojsievers
 
Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Michael Findling
 
Improving developer tester collaboration with microsoft visual studio 2010
Improving developer tester collaboration with microsoft visual studio 2010Improving developer tester collaboration with microsoft visual studio 2010
Improving developer tester collaboration with microsoft visual studio 2010Spiffy
 
Spring framework
Spring frameworkSpring framework
Spring frameworkvietduc17
 

Similar to ZF and Doctrine Integration: A Deep Dive (20)

LoneStarPHP Symfony2, Its Play Time
LoneStarPHP Symfony2, Its Play TimeLoneStarPHP Symfony2, Its Play Time
LoneStarPHP Symfony2, Its Play Time
 
An introduction to the Spring Framework
An introduction to the Spring FrameworkAn introduction to the Spring Framework
An introduction to the Spring Framework
 
eZ Publish 5 in depth inspection
eZ Publish 5 in depth inspectioneZ Publish 5 in depth inspection
eZ Publish 5 in depth inspection
 
BoxGrinder – FUDCon 2011 Tempe
BoxGrinder – FUDCon 2011 TempeBoxGrinder – FUDCon 2011 Tempe
BoxGrinder – FUDCon 2011 Tempe
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
 
BoxGrinder – FOSDEM 2012
BoxGrinder – FOSDEM 2012BoxGrinder – FOSDEM 2012
BoxGrinder – FOSDEM 2012
 
A journey with Target Platforms
A journey with Target PlatformsA journey with Target Platforms
A journey with Target Platforms
 
Entity Framework
Entity FrameworkEntity Framework
Entity Framework
 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend Framework
 
EF Core (RC2)
EF Core (RC2)EF Core (RC2)
EF Core (RC2)
 
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...
Make Me an Eclipse View (with less Plumbing): The PTP External Tools Framewor...
 
.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16.NET Core, ASP.NET Core Course, Session 16
.NET Core, ASP.NET Core Course, Session 16
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's Skeleton
 
Sling IDE Tooling
Sling IDE ToolingSling IDE Tooling
Sling IDE Tooling
 
From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm i
 
Building Eclipse Plugins and RCP applications with Tycho
Building Eclipse Plugins and RCP applications with TychoBuilding Eclipse Plugins and RCP applications with Tycho
Building Eclipse Plugins and RCP applications with Tycho
 
Code generation
Code generationCode generation
Code generation
 
Application Development | Delphi Review 2009
Application Development | Delphi Review 2009Application Development | Delphi Review 2009
Application Development | Delphi Review 2009
 
Improving developer tester collaboration with microsoft visual studio 2010
Improving developer tester collaboration with microsoft visual studio 2010Improving developer tester collaboration with microsoft visual studio 2010
Improving developer tester collaboration with microsoft visual studio 2010
 
Spring framework
Spring frameworkSpring framework
Spring framework
 

More from Benjamin Eberlei

Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleBenjamin Eberlei
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleBenjamin Eberlei
 
Framework-Qualität: Tests als Gütesiegel
Framework-Qualität: Tests als GütesiegelFramework-Qualität: Tests als Gütesiegel
Framework-Qualität: Tests als GütesiegelBenjamin Eberlei
 

More from Benjamin Eberlei (6)

Introduction to Tideways
Introduction to TidewaysIntroduction to Tideways
Introduction to Tideways
 
Doctrine and NoSQL
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
 
Doctrine for NoSQL
Doctrine for NoSQLDoctrine for NoSQL
Doctrine for NoSQL
 
Unittesting Bad-Practices by Example
Unittesting Bad-Practices by ExampleUnittesting Bad-Practices by Example
Unittesting Bad-Practices by Example
 
Unit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by ExampleUnit-Testing Bad-Practices by Example
Unit-Testing Bad-Practices by Example
 
Framework-Qualität: Tests als Gütesiegel
Framework-Qualität: Tests als GütesiegelFramework-Qualität: Tests als Gütesiegel
Framework-Qualität: Tests als Gütesiegel
 

Recently uploaded

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

ZF and Doctrine Integration: A Deep Dive

  • 1. Just married: Zend Framework and Doctrine Benjamin Eberlei direkt effekt GmbH IPC Spring 2010 Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 1 / 55
  • 2. About Me Benjamin Eberlei direkt effekt GmBH (digital marketing) Open Source contributor (Zend Framework and Doctrine) Twitter @beberlei Blog: www.whitewashing.de Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 2 / 55
  • 3. And You? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 3 / 55
  • 4. Model vs Persistence Model = Your code Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 4 / 55
  • 5. Model vs Persistence Persistence = Framework Code Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 5 / 55
  • 6. Model vs Persistence Model = Your code Persistence = Framework Code You can implement the same business logic using any persistence solution out there! Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 6 / 55
  • 7. Zend Framework Persistence Zend Db - Abstraction Layer Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 7 / 55
  • 8. Zend Framework Persistence Zend Db - Abstraction Layer Zend Db Select - SQL Query Object Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 7 / 55
  • 9. Zend Framework Persistence Zend Db - Abstraction Layer Zend Db Select - SQL Query Object Zend Db Table - Table/Row Data Gateway pattern Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 7 / 55
  • 10. Zend Framework Persistence Zend Db - Abstraction Layer Zend Db Select - SQL Query Object Zend Db Table - Table/Row Data Gateway pattern No Object-Relational Mapping Support! Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 7 / 55
  • 11. Doctrine 1 Object-Relational Mapping, Active Record Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 8 / 55
  • 12. Doctrine 1 Object-Relational Mapping, Active Record Doctrine Query Language Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 8 / 55
  • 13. Doctrine 1 Object-Relational Mapping, Active Record Doctrine Query Language Hydrators Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 8 / 55
  • 14. Doctrine 1 Object-Relational Mapping, Active Record Doctrine Query Language Hydrators Database Migrations Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 8 / 55
  • 15. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 16. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap 2. Define a YAML Schema Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 17. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap 2. Define a YAML Schema 3. Generate Model and Table PHP classes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 18. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap 2. Define a YAML Schema 3. Generate Model and Table PHP classes 4. Generate Database Schema from Models Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 19. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap 2. Define a YAML Schema 3. Generate Model and Table PHP classes 4. Generate Database Schema from Models 5. Repeat (2)-(4) for Iterations of your models. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 20. Doctrine Modelling Workflow 1. Setup Doctrine Bootstrap 2. Define a YAML Schema 3. Generate Model and Table PHP classes 4. Generate Database Schema from Models 5. Repeat (2)-(4) for Iterations of your models. 6. In production, use migrations for schema evolvement. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 9 / 55
  • 21. A Doctrine Project Layout Non-PEAR Structure Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 10 / 55
  • 22. A Doctrine Project Layout Non-PEAR Structure No Module Prefixes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 10 / 55
  • 23. A Doctrine Project Layout Non-PEAR Structure No Module Prefixes Autoloading? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 10 / 55
  • 24. A Doctrine Project Layout Non-PEAR Structure No Module Prefixes Autoloading? Configurable (PEAR).. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 10 / 55
  • 25. A Doctrine Project Layout Non-PEAR Structure No Module Prefixes Autoloading? Configurable (PEAR).. ..Not enough for ZF! Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 10 / 55
  • 26. Zend Framework Projects Model * in models/ Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 11 / 55
  • 27. Zend Framework Projects Model * in models/ Single Module Project Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 11 / 55
  • 28. Zend Framework Projects Model * in models/ Single Module Project Not PEAR Standard Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 11 / 55
  • 29. Zend Framework Projects Model * in models/ Single Module Project Not PEAR Standard Special Autoloader Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 11 / 55
  • 30. Modular ZF Project Each Module has models/ Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 12 / 55
  • 31. Modular ZF Project Each Module has models/ Again Special Autoloader Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 12 / 55
  • 32. ZF + Doctrine Integration Not a ZF Component Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 33. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 34. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 35. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Includes: 1. Zend Application Resource Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 36. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Includes: 1. Zend Application Resource 2. Zend Tool Integration Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 37. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Includes: 1. Zend Application Resource 2. Zend Tool Integration 3. Zend Forms from Doctrine Metadata Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 38. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Includes: 1. Zend Application Resource 2. Zend Tool Integration 3. Zend Forms from Doctrine Metadata 4. Paginator Adapter Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 39. ZF + Doctrine Integration Not a ZF Component Download: http://github.com/beberlei/zf-doctrine One Goal: No code-generation Includes: 1. Zend Application Resource 2. Zend Tool Integration 3. Zend Forms from Doctrine Metadata 4. Paginator Adapter 5. Model List View Helper Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 13 / 55
  • 40. Zend Application Resource 1. Install using Zend Tool: zf create project forum zf create-project doctrine –dsn=$DSN Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 14 / 55
  • 41. Zend Application Resource 2. Register manually with Zend Application resources . doctrine . connections . default . dsn = " " pluginpaths . Z F D o c t r i n e _ A p p l i c a t i o n _ R e s o u r c e = " ZFDoctrine / Application / Resource " a u toloade r n a m e s p a c e s [] = " Doctrine " a u toloade r n a m e s p a c e s [] = " ZFDoctrine . Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 15 / 55
  • 42. Configuring the Application Resource Configuring Connection DSN resources . doctrine . connections . < name >. dsn Configuring Connection Attributes resources . doctrine . connections . < name >. attributes Configuring Manager Attributes resources . doctrine . manager . attributes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 16 / 55
  • 43. ZFDoctrine Conventions Both ZF 1 and Doctrine 1 are magic boxes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 17 / 55
  • 44. ZFDoctrine Conventions Both ZF 1 and Doctrine 1 are magic boxes Enforcing Conventions Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 17 / 55
  • 45. ZFDoctrine Conventions Both ZF 1 and Doctrine 1 are magic boxes Enforcing Conventions Model Classes: $Module Model $Name: 1. Default Model User 2. Default Model Group 3. Forum Model Thread 4. Forum Model Board Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 17 / 55
  • 46. ZFDoctrine Conventions Both ZF 1 and Doctrine 1 are magic boxes Enforcing Conventions Model Classes: $Module Model $Name: 1. Default Model User 2. Default Model Group 3. Forum Model Thread 4. Forum Model Board Define Metadata Attributes refClass, local, model and foreign explicitly Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 17 / 55
  • 47. A Doctrine Project zf create project forum zf create-project doctrine –dsn Creating four essential Doctrine Directories: application/configs/schema application/configs/fixtures application/configs/migrations application/configs/sql Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 18 / 55
  • 48. Example Yaml schema: Forum Put a forum.yml in the schema directory: F o rum_Mod e l _ C a t e g o r y : columns : name : string (50) description : string (99999) Forum_Mode l_Boar d : columns : category_id : integer (10) name : string (100) description : string (5000) relations : Category : class : F o r u m _ Model_Category local : category_id foreign : id Threads : class : Fo ru m_ Model_Thread local : id foreign : board_id Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 19 / 55
  • 49. Generate Models from Yaml zf generate-models-from-yaml doctrine Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 20 / 55
  • 50. Generate Models from Yaml zf generate-models-from-yaml doctrine Generate Table Classes (application.ini) resources . doctrine . generateModels . generateTableClasses = true Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 20 / 55
  • 51. Generate Models Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 21 / 55
  • 52. Generate Models Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 22 / 55
  • 53. Generated Model Classes Records Base Records Tables Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 23 / 55
  • 54. Code Generation? Doctrine creates Models from Yaml files. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 24 / 55
  • 55. Code Generation? Doctrine creates Models from Yaml files. ...optionally(!) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 24 / 55
  • 56. Code Generation? Doctrine creates Models from Yaml files. ...optionally(!) You can skip Yaml and directly code the Model (Records and Tables) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 24 / 55
  • 57. Code Generation? Doctrine creates Models from Yaml files. ...optionally(!) You can skip Yaml and directly code the Model (Records and Tables) Zend Framework Project Support works without Yaml. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 24 / 55
  • 58. Generated Record: class For u m _ M o de l _ C ategory extends Forum_Model_Base_Category { } Generated Table: class F o r u m _ M o d e l _ C a t e g o r y T a b le extends Doctrine_Table { public static function getInstance () { return Doctrine_Core :: getTable ( ’ F o r u m _ Model_Category ’) ; } } Generated Base Record: Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 25 / 55
  • 59. abstract class F o r u m _ M o d e l _ B a s e _ C a t e g o r y extends Doctrine_Record { public function setTableDefinition () { $this - > setTableName ( ’ forum_categories ’) ; $this - > hasColumn ( ’ name ’ , ’ string ’ , 50 , array ( ’ type ’ = > ’ string ’ , ’ length ’ = > ’ 50 ’ , )); $this - > hasColumn ( ’ description ’ , ’ string ’ , 99999 , array ( ’ type ’ = > ’ string ’ , ’ length ’ = > ’ 99999 ’ , )); } public function setUp () { parent :: setUp () ; $this - > hasMany ( ’ Forum_Model_Board ’ , array ( ’ local ’ = > ’ id ’ , ’ foreign ’ = > ’ category_id ’) ) ; } } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 26 / 55
  • 60. Generating Database zf build-project doctrine –reload Drop and Create Database Create Tables Load Fixtures Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 27 / 55
  • 61. Migrations Update your Database Schema: zf show-migration doctrine Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 28 / 55
  • 62. Migrations Update your Database Schema: zf show-migration doctrine zf generate-migration doctrine Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 28 / 55
  • 63. Migrations Update your Database Schema: zf show-migration doctrine zf generate-migration doctrine zf execute-migration doctrine Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 28 / 55
  • 64. Forms for Doctrine Models Using Doctrine Metadata for other, non ORM purposes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 29 / 55
  • 65. Forms for Doctrine Models Using Doctrine Metadata for other, non ORM purposes Configuration of Zend Form instances Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 29 / 55
  • 66. Forms for Doctrine Models Using Doctrine Metadata for other, non ORM purposes Configuration of Zend Form instances Mostly for backend (scaffolding) purposes Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 29 / 55
  • 67. A Simple Form $form = new Z F D o c t r i ne_Fr om_M odel ( array ( ’ model ’ = > ’ F o r um_Model_Category ’ , ’ action ’ = > ’. ’ , ’ method ’ = > ’ post ’ )); Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 30 / 55
  • 68. A Simple Form: Tweaking $form = new Z F D o c t r i ne_Fo rm_M odel ( array ( ’ model ’ = > ’ F o r um_Model_Category ’ , ’ method ’ = > ’ post ’ , ’ action ’ = > $this - > _helper - > url ( ’add - category ’ , ’ admin ’) , ’ fieldLabels ’ = > array ( ’ name ’ = > ’ Name ’ , ’ description ’ = > ’ Description ’ , ), ’ fieldTypes ’ = > array ( ’ description ’ = > ’ textarea ’ , ), )); Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 31 / 55
  • 69. A Simple Form: Tweaking Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 32 / 55
  • 70. A Simple Form: Controller public function add CategoryAction () { $form = $this - > createCategoryForm () ; $request = $this - > getRequest () ; $post = $request - > getPost () ; if ( $request - > isPost () && $form - > isValid ( $post ) ) { $form - > save () ; $this - > _helper - > redirector ( ’ success ’ , ’ admin ’) ; } $this - > view - > form = $form ; } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 33 / 55
  • 71. A Simple Form: Updating public function e di tCategoryAction () { $categoryId = $this - > _getParam ( ’ id ’) ; $form = $this - > createCategoryForm () ; $request = $this - > getRequest () ; $post = $request - > getPost () ; $table = Doctrine :: getTable ( ’ Forum_Model_Category ’) ; $category = $table - > find ( $categoryId ) ; $form - > setRecord ( $category ) ; if ( $request - > isPost () && $form - > isValid ( $post ) ) { $form - > save () ; $this - > _helper - > redirector ( ’ success ’ , ’ admin ’) ; } $this - > view - > form = $form ; } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 34 / 55
  • 72. A Simple Form: Action Helper public function add CategoryAction () { $form = $this - > createCategoryForm () ; $this - > _helper - > modelForm ( $form , ’ success ’) ; } public function e di tCategoryAction () { $form = $this - > createCategoryForm () ; $this - > getHelper ( ’ modelForm ’) -> setRecordIdParam ( ’ id ’) -> handleForm ( $form , ’ success ’) ; } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 35 / 55
  • 73. Advanced Forms: Relations Relations rendered as (multi-)select fields: public function addBoardAction () { $form = new Z F D o ctri ne_Fo rm_M odel ( array ( ’ model ’ = > ’ Forum_Model_Board ’ , )); $this - > _helper - > modelForm ( $form , " success " ) ; } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 36 / 55
  • 74. Advanced Forms: Relations Relations rendered as (multi-)select fields: public function addBoardAction () { $form = new Z F D o ctri ne_Fo rm_M odel ( array ( ’ model ’ = > ’ Forum_Model_Board ’ , )); $this - > _helper - > modelForm ( $form , " success " ) ; } Control Option Labels: class For u m _ M o del _ C a tegory extends ... { public function __toString () { return $this - > id . " , " . $this - > name ; } } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 36 / 55
  • 75. Advanced Forms: Relations Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 37 / 55
  • 76. Advanced Forms: Hooks Add Validators and Filters Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 38 / 55
  • 77. Advanced Forms: Hooks Add Validators and Filters Change Decorators Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 38 / 55
  • 78. Advanced Forms: Hooks Add Validators and Filters Change Decorators Use jQuery or Dojo Integration Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 38 / 55
  • 79. Advanced Forms: Hooks Add Validators and Filters Change Decorators Use jQuery or Dojo Integration Hook methods: preGenerate() and postGenerate() Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 38 / 55
  • 80. Advanced Forms: Hooks Adding decorators in preGenerate(): class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del { protected function _preGenerate () { // called before the form is generated $decorators = array ( ’ FormElements ’ , array ( array ( ’ data ’= > ’ HtmlTag ’) , array ( ’ tag ’= > ’ table ’) ) , ’ Form ’ ); $this - > setDecorators ( $decorators ) ; } } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 39 / 55
  • 81. Advanced Forms: Hooks jQuery or Dojo Enable a Form: class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del { protected function _preGenerate () { ZendX_JQuery :: enableForm ( $this ) ; // Zend_Dojo :: enableForm ( $this ) ; } } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 40 / 55
  • 82. Advanced Forms: Hooks Adding a validator in postGenerate(): class Forum _Form_T hread extends ZFDo ctrin e_Fo rm_Mo del { protected function _postGenerate () { // called after the form is generated $validator = new Z e n d _ V a l i d a t e _ S t r i n g L e n g t h ( array ( ’ min ’ = > 5 , ’ max ’ = > 255) ); $this - > getElement ( ’ title ’) -> addValidator ( $validator ) ; } } Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 41 / 55
  • 83. Paginator Adapter Paginate a Doctrine Query: $query = Doctrine_Query :: create () ; // $query ... $adapter = new Z F D o c t r i n e _ P a g i n a t o r _ A d a p t e r _ D o c t r i n e Q u e r y ( $query ) ; $paginator = new Zend_Paginator ( $adapter ) ; Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 42 / 55
  • 84. Paginator Adapter Paginate a Doctrine Query: $query = Doctrine_Query :: create () ; // $query ... $adapter = new Z F D o c t r i n e _ P a g i n a t o r _ A d a p t e r _ D o c t r i n e Q u e r y ( $query ) ; $paginator = new Zend_Paginator ( $adapter ) ; Paginate a Doctrine Table: $table = Doctrine_Core :: getTable ( ’ MyModel ’) ; $query = $table - > createQuery () ; Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 42 / 55
  • 85. Model List View Helper Creates a paginated list for a model Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 43 / 55
  • 86. Model List View Helper Creates a paginated list for a model Links to CRUD actions Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 43 / 55
  • 87. Model List View Helper Creates a paginated list for a model Links to CRUD actions Reasonable default Look & Feel Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 43 / 55
  • 88. Model List View Helper Creates a paginated list for a model Links to CRUD actions Reasonable default Look & Feel But offers full customization Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 43 / 55
  • 89. Model List View Helper <h1 > Boards </ h1 > <?= $this - > modelList ( ’ Forum_Model_Board ’) ; ? > Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 44 / 55
  • 90. Model List View Helper <h1 > Boards </ h1 > <?= $this - > modelList ( ’ Forum_Model_Board ’) ; ? > <h1 > Boards </ h1 > <?= $this - > modelList ( ’ Forum_Model_Board ’ , array ( ’ editRecordAction ’ = > ’ edit - board ’ , ’ addRecordAction ’ = > ’add - board ’ , ’ fieldLabels ’ = > array ( ’ id ’ = > ’ ID ’ , ’ category_id ’ = > ’ Category ’ , ’ name ’ = > ’ Name ’ , ’ description ’ = > ’ Description ’ , ) )); ?> Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 44 / 55
  • 91. Model List View Helper Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 45 / 55
  • 92. Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 46 / 55
  • 93. Questions? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 47 / 55
  • 94. Zend Framework 2.0 Currently Conversion to Namespaces Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 48 / 55
  • 95. Zend Framework 2.0 Currently Conversion to Namespaces Specified Goals: 1. Ease the learning curve 2. Make extending the framework trivially simple 3. Simplify 4. Favor the explicit over the magical Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 48 / 55
  • 96. Zend Framework 2.0 Currently Conversion to Namespaces Specified Goals: 1. Ease the learning curve 2. Make extending the framework trivially simple 3. Simplify 4. Favor the explicit over the magical ETA Q4/2010 or Q1/2011 Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 48 / 55
  • 97. Doctrine 2 Separation of DBAL and ORM Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 98. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 99. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design DataMapper instead of ActiveRecord Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 100. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design DataMapper instead of ActiveRecord Powerful Metadata Mapping Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 101. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design DataMapper instead of ActiveRecord Powerful Metadata Mapping Considerable Performance Improvements Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 102. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design DataMapper instead of ActiveRecord Powerful Metadata Mapping Considerable Performance Improvements Currently Beta 1, Release on September 1st Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 103. Doctrine 2 Separation of DBAL and ORM Less Magic, More Explicit Design DataMapper instead of ActiveRecord Powerful Metadata Mapping Considerable Performance Improvements Currently Beta 1, Release on September 1st First class citizen in Symfony 2 Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 49 / 55
  • 104. Wednesday, 8:30, Room Salon 1 Guilherme on Doctrine 2! Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 50 / 55
  • 105. Doctrine 2 DBAL PDO API (ezcDatabase) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 106. Doctrine 2 DBAL PDO API (ezcDatabase) Currently Support for MySql, PgSql, Oracle, Sqlite, IBM and PDO Db2 Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 107. Doctrine 2 DBAL PDO API (ezcDatabase) Currently Support for MySql, PgSql, Oracle, Sqlite, IBM and PDO Db2 SqlSrv (+PDO) under development Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 108. Doctrine 2 DBAL PDO API (ezcDatabase) Currently Support for MySql, PgSql, Oracle, Sqlite, IBM and PDO Db2 SqlSrv (+PDO) under development Lots of Convenience Methods (Zend Db) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 109. Doctrine 2 DBAL PDO API (ezcDatabase) Currently Support for MySql, PgSql, Oracle, Sqlite, IBM and PDO Db2 SqlSrv (+PDO) under development Lots of Convenience Methods (Zend Db) Currently planned: A Query Object (Zend Db Select, ezcDatabaseQuery) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 110. Doctrine 2 DBAL PDO API (ezcDatabase) Currently Support for MySql, PgSql, Oracle, Sqlite, IBM and PDO Db2 SqlSrv (+PDO) under development Lots of Convenience Methods (Zend Db) Currently planned: A Query Object (Zend Db Select, ezcDatabaseQuery) SQL DDL and Data-QL abstraction (PEAR MDB2 and ezcDatabaseSchema) Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 51 / 55
  • 111. Doctrine 2 DBAL Schema An OO-Approach to Database Schema Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 52 / 55
  • 112. Doctrine 2 DBAL Schema An OO-Approach to Database Schema Vendor independent abstraction of Tables, Indexes, ForeignKeys and Sequences Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 52 / 55
  • 113. Doctrine 2 DBAL Schema An OO-Approach to Database Schema Vendor independent abstraction of Tables, Indexes, ForeignKeys and Sequences Get required set-up or tear-down SQL Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 52 / 55
  • 114. Doctrine 2 DBAL Schema An OO-Approach to Database Schema Vendor independent abstraction of Tables, Indexes, ForeignKeys and Sequences Get required set-up or tear-down SQL Get SQL to move from one to another schema Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 52 / 55
  • 115. Doctrine 2 DBAL Schema An OO-Approach to Database Schema Vendor independent abstraction of Tables, Indexes, ForeignKeys and Sequences Get required set-up or tear-down SQL Get SQL to move from one to another schema Doctrine Migrations Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 52 / 55
  • 116. ZF 2 with Doctrine DBAL 2 First class support? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 53 / 55
  • 117. ZF 2 with Doctrine DBAL 2 First class support? Doctrine 2 DBAL API compatible with Zend Db? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 53 / 55
  • 118. ZF 2 with Doctrine DBAL 2 First class support? Doctrine 2 DBAL API compatible with Zend Db? Zend Db Select drop-in replacement? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 53 / 55
  • 119. ZF 2 with Doctrine DBAL 2 First class support? Doctrine 2 DBAL API compatible with Zend Db? Zend Db Select drop-in replacement? Table-, Row-Data-Gateway? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 53 / 55
  • 120. ZF 2 with Doctrine DBAL 2 First class support? Doctrine 2 DBAL API compatible with Zend Db? Zend Db Select drop-in replacement? Table-, Row-Data-Gateway? ORM Integration? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 53 / 55
  • 121. Questions? Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 54 / 55
  • 122. Thank You! Please rate this talk on joind.in: http://joind.in/1710 Twitter: @beberlei Blog: http://www.whitewashing.de Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 55 / 55