122
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

Just Married: Zend Framework and Doctrine

Embed Size (px)

DESCRIPTION

Zend Framework and Doctrine 1 are bundled in many applications although no formal integration between both existed up to now. This talk shows how we integrated both Doctrines as a possible modelling layer for the latest Zend Framework release and merged together the combined wisdom of both communities. An in-depth preview of Doctrine 2 and ZF integration completes the topic of this talk.

Citation preview

Page 1: Just Married: Zend Framework and Doctrine

Just married: ZendFramework and Doctrine

Benjamin Eberlei

direkt effekt GmbH

IPC Spring 2010

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

Page 2: Just Married: Zend Framework and Doctrine

About Me

I Benjamin Eberlei

I direkt effekt GmBH

(digital marketing)

I Open Source contributor

(Zend Framework and Doctrine)

I Twitter @beberlei

I Blog: www.whitewashing.de

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

Page 3: Just Married: Zend Framework and Doctrine

And You?

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

Page 4: Just Married: Zend Framework and Doctrine

Model vs Persistence

Model=

Your code

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

Page 5: Just Married: Zend Framework and Doctrine

Model vs Persistence

Persistence=

Framework Code

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

Page 6: Just Married: Zend Framework and Doctrine

Model vs Persistence

I Model = Your code

I Persistence = Framework Code

I You can implement the samebusiness logic using any persistencesolution out there!

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

Page 7: Just Married: Zend Framework and Doctrine

Zend Framework Persistence

I Zend Db - Abstraction Layer

I Zend Db Select - SQL Query Object

I Zend Db Table - Table/Row DataGateway pattern

No Object-Relational Mapping Support!

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

Page 8: Just Married: Zend Framework and Doctrine

Zend Framework Persistence

I Zend Db - Abstraction Layer

I Zend Db Select - SQL Query Object

I Zend Db Table - Table/Row DataGateway pattern

No Object-Relational Mapping Support!

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

Page 9: Just Married: Zend Framework and Doctrine

Zend Framework Persistence

I Zend Db - Abstraction Layer

I Zend Db Select - SQL Query Object

I Zend Db Table - Table/Row DataGateway pattern

No Object-Relational Mapping Support!

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

Page 10: Just Married: Zend Framework and Doctrine

Zend Framework Persistence

I Zend Db - Abstraction Layer

I Zend Db Select - SQL Query Object

I Zend Db Table - Table/Row DataGateway pattern

No Object-Relational Mapping Support!

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

Page 11: Just Married: Zend Framework and Doctrine

Doctrine 1

I Object-Relational Mapping, Active Record

I Doctrine Query Language

I Hydrators

I Database Migrations

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

Page 12: Just Married: Zend Framework and Doctrine

Doctrine 1

I Object-Relational Mapping, Active Record

I Doctrine Query Language

I Hydrators

I Database Migrations

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

Page 13: Just Married: Zend Framework and Doctrine

Doctrine 1

I Object-Relational Mapping, Active Record

I Doctrine Query Language

I Hydrators

I Database Migrations

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

Page 14: Just Married: Zend Framework and Doctrine

Doctrine 1

I Object-Relational Mapping, Active Record

I Doctrine Query Language

I Hydrators

I Database Migrations

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

Page 15: Just Married: Zend Framework and Doctrine

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

Page 16: Just Married: Zend Framework and Doctrine

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

Page 17: Just Married: Zend Framework and Doctrine

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

Page 18: Just Married: Zend Framework and Doctrine

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

Page 19: Just Married: Zend Framework and Doctrine

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

Page 20: Just Married: Zend Framework and Doctrine

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

Page 21: Just Married: Zend Framework and Doctrine

A Doctrine Project Layout

I Non-PEAR Structure

I No Module Prefixes

I Autoloading?

I Configurable (PEAR)..

I ..Not enough for ZF!

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

Page 22: Just Married: Zend Framework and Doctrine

A Doctrine Project Layout

I Non-PEAR Structure

I No Module Prefixes

I Autoloading?

I Configurable (PEAR)..

I ..Not enough for ZF!

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

Page 23: Just Married: Zend Framework and Doctrine

A Doctrine Project Layout

I Non-PEAR Structure

I No Module Prefixes

I Autoloading?

I Configurable (PEAR)..

I ..Not enough for ZF!

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

Page 24: Just Married: Zend Framework and Doctrine

A Doctrine Project Layout

I Non-PEAR Structure

I No Module Prefixes

I Autoloading?

I Configurable (PEAR)..

I ..Not enough for ZF!

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

Page 25: Just Married: Zend Framework and Doctrine

A Doctrine Project Layout

I Non-PEAR Structure

I No Module Prefixes

I Autoloading?

I Configurable (PEAR)..

I ..Not enough for ZF!

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

Page 26: Just Married: Zend Framework and Doctrine

Zend Framework Projects

I Model * in models/

I Single Module Project

I Not PEAR Standard

I Special Autoloader

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

Page 27: Just Married: Zend Framework and Doctrine

Zend Framework Projects

I Model * in models/

I Single Module Project

I Not PEAR Standard

I Special Autoloader

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

Page 28: Just Married: Zend Framework and Doctrine

Zend Framework Projects

I Model * in models/

I Single Module Project

I Not PEAR Standard

I Special Autoloader

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

Page 29: Just Married: Zend Framework and Doctrine

Zend Framework Projects

I Model * in models/

I Single Module Project

I Not PEAR Standard

I Special Autoloader

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

Page 30: Just Married: Zend Framework and Doctrine

Modular ZF Project

I Each Module has models/

I Again Special Autoloader

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

Page 31: Just Married: Zend Framework and Doctrine

Modular ZF Project

I Each Module has models/

I Again Special Autoloader

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

Page 32: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 33: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 34: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generation

I Includes:1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 35: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource

2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 36: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration

3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 37: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata

4. Paginator Adapter5. Model List View Helper

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

Page 38: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter

5. Model List View Helper

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

Page 39: Just Married: Zend Framework and Doctrine

ZF + Doctrine Integration

I Not a ZF Component

I Download:

http://github.com/beberlei/zf-doctrine

I One Goal: No code-generationI Includes:

1. Zend Application Resource2. Zend Tool Integration3. Zend Forms from Doctrine Metadata4. Paginator Adapter5. Model List View Helper

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

Page 40: Just Married: Zend Framework and Doctrine

Zend Application Resource

1. Install using Zend Tool:

zf create project forumzf create-project doctrine –dsn=$DSN

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

Page 41: Just Married: Zend Framework and Doctrine

Zend Application Resource

2. Register manually with Zend Applicationresources.doctrine.connections.default.dsn = ""pluginpaths.ZFDoctrine_Application_Resource

= "ZFDoctrine/Application/Resource"autoloadernamespaces [] = "Doctrine"autoloadernamespaces [] = "ZFDoctrine

.

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

Page 42: Just Married: Zend Framework and Doctrine

Configuring the ApplicationResource

Configuring Connection DSNresources.doctrine.connections.<name >.dsn

Configuring Connection Attributesresources.doctrine.connections.<name >. attributes

Configuring Manager Attributesresources.doctrine.manager.attributes

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

Page 43: Just Married: Zend Framework and Doctrine

ZFDoctrine Conventions

I Both ZF 1 and Doctrine 1 are magic boxes

I Enforcing ConventionsI Model Classes: $Module Model $Name:

1. Default Model User2. Default Model Group3. Forum Model Thread4. Forum Model Board

I Define Metadata Attributes refClass, local,

model and foreign explicitly

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

Page 44: Just Married: Zend Framework and Doctrine

ZFDoctrine Conventions

I Both ZF 1 and Doctrine 1 are magic boxes

I Enforcing Conventions

I Model Classes: $Module Model $Name:1. Default Model User2. Default Model Group3. Forum Model Thread4. Forum Model Board

I Define Metadata Attributes refClass, local,

model and foreign explicitly

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

Page 45: Just Married: Zend Framework and Doctrine

ZFDoctrine Conventions

I Both ZF 1 and Doctrine 1 are magic boxes

I Enforcing ConventionsI Model Classes: $Module Model $Name:

1. Default Model User2. Default Model Group3. Forum Model Thread4. Forum Model Board

I Define Metadata Attributes refClass, local,

model and foreign explicitly

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

Page 46: Just Married: Zend Framework and Doctrine

ZFDoctrine Conventions

I Both ZF 1 and Doctrine 1 are magic boxes

I Enforcing ConventionsI Model Classes: $Module Model $Name:

1. Default Model User2. Default Model Group3. Forum Model Thread4. Forum Model Board

I Define Metadata Attributes refClass, local,

model and foreign explicitly

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

Page 47: Just Married: Zend Framework and Doctrine

A Doctrine Project

zf create project forumzf create-project doctrine –dsn

Creating four essential Doctrine Directories:

I application/configs/schema

I application/configs/fixtures

I application/configs/migrations

I application/configs/sql

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

Page 48: Just Married: Zend Framework and Doctrine

Example Yaml schema: Forum

Put a forum.yml in the schema directory:Forum_Model_Category:

columns:name: string (50)description: string (99999)

Forum_Model_Board:columns:

category_id: integer (10)name: string (100)description: string (5000)

relations:Category:

class: Forum_Model_Categorylocal: category_idforeign: id

Threads:class: Forum_Model_Threadlocal: idforeign: board_id

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

Page 49: Just Married: Zend Framework and Doctrine

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

Page 50: Just Married: Zend Framework and Doctrine

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

Page 51: Just Married: Zend Framework and Doctrine

Generate Models

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

Page 52: Just Married: Zend Framework and Doctrine

Generate Models

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

Page 53: Just Married: Zend Framework and Doctrine

Generated Model Classes

I Records

I Base Records

I Tables

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

Page 54: Just Married: Zend Framework and Doctrine

Code Generation?

I Doctrine creates Models from Yaml files.

I ...optionally(!)

I You can skip Yaml and directly code the

Model (Records and Tables)

I Zend Framework Project Support works

without Yaml.

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

Page 55: Just Married: Zend Framework and Doctrine

Code Generation?

I Doctrine creates Models from Yaml files.

I ...optionally(!)

I You can skip Yaml and directly code the

Model (Records and Tables)

I Zend Framework Project Support works

without Yaml.

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

Page 56: Just Married: Zend Framework and Doctrine

Code Generation?

I Doctrine creates Models from Yaml files.

I ...optionally(!)

I You can skip Yaml and directly code the

Model (Records and Tables)

I Zend Framework Project Support works

without Yaml.

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

Page 57: Just Married: Zend Framework and Doctrine

Code Generation?

I Doctrine creates Models from Yaml files.

I ...optionally(!)

I You can skip Yaml and directly code the

Model (Records and Tables)

I Zend Framework Project Support works

without Yaml.

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

Page 58: Just Married: Zend Framework and Doctrine

Generated Record:class Forum_Model_Category extends

Forum_Model_Base_Category{}

Generated Table:class Forum_Model_CategoryTable extends Doctrine_Table{

public static function getInstance (){

return Doctrine_Core :: getTable(’Forum_Model_Category ’);

}}

Generated Base Record:

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

Page 59: Just Married: Zend Framework and Doctrine

abstract class Forum_Model_Base_Category extendsDoctrine_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

Page 60: Just Married: Zend Framework and Doctrine

Generating Database

zf build-project doctrine –reload

I Drop and Create Database

I Create Tables

I Load Fixtures

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

Page 61: Just Married: Zend Framework and Doctrine

Migrations

Update your Database Schema:

I zf show-migration doctrine

I zf generate-migration doctrine

I zf execute-migration doctrine

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

Page 62: Just Married: Zend Framework and Doctrine

Migrations

Update your Database Schema:

I zf show-migration doctrine

I zf generate-migration doctrine

I zf execute-migration doctrine

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

Page 63: Just Married: Zend Framework and Doctrine

Migrations

Update your Database Schema:

I zf show-migration doctrine

I zf generate-migration doctrine

I zf execute-migration doctrine

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

Page 64: Just Married: Zend Framework and Doctrine

Forms for Doctrine Models

I Using Doctrine Metadata for other, non

ORM purposes

I Configuration of Zend Form instances

I Mostly for backend (scaffolding) purposes

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

Page 65: Just Married: Zend Framework and Doctrine

Forms for Doctrine Models

I Using Doctrine Metadata for other, non

ORM purposes

I Configuration of Zend Form instances

I Mostly for backend (scaffolding) purposes

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

Page 66: Just Married: Zend Framework and Doctrine

Forms for Doctrine Models

I Using Doctrine Metadata for other, non

ORM purposes

I Configuration of Zend Form instances

I Mostly for backend (scaffolding) purposes

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

Page 67: Just Married: Zend Framework and Doctrine

A Simple Form

$form = new ZFDoctrine_From_Model(array(’model ’ => ’Forum_Model_Category ’,’action ’ => ’.’,’method ’ => ’post’

));

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

Page 68: Just Married: Zend Framework and Doctrine

A Simple Form: Tweaking

$form = new ZFDoctrine_Form_Model(array(’model ’ => ’Forum_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

Page 69: Just Married: Zend Framework and Doctrine

A Simple Form: Tweaking

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

Page 70: Just Married: Zend Framework and Doctrine

A Simple Form: Controller

public function addCategoryAction (){

$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

Page 71: Just Married: Zend Framework and Doctrine

A Simple Form: Updating

public function editCategoryAction (){

$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

Page 72: Just Married: Zend Framework and Doctrine

A Simple Form: Action Helper

public function addCategoryAction (){

$form = $this ->createCategoryForm ();$this ->_helper ->modelForm($form , ’success ’);

}

public function editCategoryAction (){

$form = $this ->createCategoryForm ();$this ->getHelper(’modelForm ’)

->setRecordIdParam(’id’)->handleForm($form , ’success ’);

}

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

Page 73: Just Married: Zend Framework and Doctrine

Advanced Forms: Relations

Relations rendered as (multi-)select fields:public function addBoardAction (){

$form = new ZFDoctrine_Form_Model(array(’model ’ => ’Forum_Model_Board ’,

));$this ->_helper ->modelForm($form , "success");

}

Control Option Labels:class Forum_Model_Category extends ...{

public function __toString () {return $this ->id . ", " . $this ->name;

}}

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

Page 74: Just Married: Zend Framework and Doctrine

Advanced Forms: Relations

Relations rendered as (multi-)select fields:public function addBoardAction (){

$form = new ZFDoctrine_Form_Model(array(’model ’ => ’Forum_Model_Board ’,

));$this ->_helper ->modelForm($form , "success");

}

Control Option Labels:class Forum_Model_Category extends ...{

public function __toString () {return $this ->id . ", " . $this ->name;

}}

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

Page 75: Just Married: Zend Framework and Doctrine

Advanced Forms: Relations

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

Page 76: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

I Add Validators and Filters

I Change Decorators

I Use jQuery or Dojo Integration

I Hook methods: preGenerate() and

postGenerate()

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

Page 77: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

I Add Validators and Filters

I Change Decorators

I Use jQuery or Dojo Integration

I Hook methods: preGenerate() and

postGenerate()

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

Page 78: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

I Add Validators and Filters

I Change Decorators

I Use jQuery or Dojo Integration

I Hook methods: preGenerate() and

postGenerate()

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

Page 79: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

I Add Validators and Filters

I Change Decorators

I Use jQuery or Dojo Integration

I Hook methods: preGenerate() and

postGenerate()

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

Page 80: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

Adding decorators in preGenerate():class Forum_Form_Thread extends ZFDoctrine_Form_Model{

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

Page 81: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

jQuery or Dojo Enable a Form:class Forum_Form_Thread extends ZFDoctrine_Form_Model{

protected function _preGenerate (){

ZendX_JQuery :: enableForm($this);// Zend_Dojo :: enableForm($this);

}}

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

Page 82: Just Married: Zend Framework and Doctrine

Advanced Forms: Hooks

Adding a validator in postGenerate():class Forum_Form_Thread extends ZFDoctrine_Form_Model{

protected function _postGenerate (){

// called after the form is generated$validator = new Zend_Validate_StringLength(

array(’min’ => 5, ’max’ => 255));$this ->getElement(’title ’)

->addValidator($validator);}

}

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

Page 83: Just Married: Zend Framework and Doctrine

Paginator Adapter

Paginate a Doctrine Query:$query = Doctrine_Query :: create (); // $query ...$adapter =

new ZFDoctrine_Paginator_Adapter_DoctrineQuery($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

Page 84: Just Married: Zend Framework and Doctrine

Paginator Adapter

Paginate a Doctrine Query:$query = Doctrine_Query :: create (); // $query ...$adapter =

new ZFDoctrine_Paginator_Adapter_DoctrineQuery($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

Page 85: Just Married: Zend Framework and Doctrine

Model List View Helper

I Creates a paginated list for a model

I Links to CRUD actions

I Reasonable default Look & Feel

I But offers full customization

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

Page 86: Just Married: Zend Framework and Doctrine

Model List View Helper

I Creates a paginated list for a model

I Links to CRUD actions

I Reasonable default Look & Feel

I But offers full customization

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

Page 87: Just Married: Zend Framework and Doctrine

Model List View Helper

I Creates a paginated list for a model

I Links to CRUD actions

I Reasonable default Look & Feel

I But offers full customization

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

Page 88: Just Married: Zend Framework and Doctrine

Model List View Helper

I Creates a paginated list for a model

I Links to CRUD actions

I Reasonable default Look & Feel

I But offers full customization

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

Page 89: Just Married: Zend Framework and Doctrine

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

Page 90: Just Married: Zend Framework and Doctrine

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

Page 91: Just Married: Zend Framework and Doctrine

Model List View Helper

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

Page 92: Just Married: Zend Framework and Doctrine

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

Page 93: Just Married: Zend Framework and Doctrine

Questions?

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

Page 94: Just Married: Zend Framework and Doctrine

Zend Framework 2.0

I Currently Conversion to Namespaces

I Specified Goals:1. Ease the learning curve2. Make extending the framework trivially

simple3. Simplify4. Favor the explicit over the magical

I ETA Q4/2010 or Q1/2011

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

Page 95: Just Married: Zend Framework and Doctrine

Zend Framework 2.0

I Currently Conversion to NamespacesI Specified Goals:

1. Ease the learning curve2. Make extending the framework trivially

simple3. Simplify4. Favor the explicit over the magical

I ETA Q4/2010 or Q1/2011

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

Page 96: Just Married: Zend Framework and Doctrine

Zend Framework 2.0

I Currently Conversion to NamespacesI Specified Goals:

1. Ease the learning curve2. Make extending the framework trivially

simple3. Simplify4. Favor the explicit over the magical

I ETA Q4/2010 or Q1/2011

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

Page 97: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 98: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 99: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 100: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 101: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 102: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 103: Just Married: Zend Framework and Doctrine

Doctrine 2

I Separation of DBAL and ORM

I Less Magic, More Explicit Design

I DataMapper instead of ActiveRecord

I Powerful Metadata Mapping

I Considerable Performance Improvements

I Currently Beta 1, Release on September 1st

I First class citizen in Symfony 2

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

Page 104: Just Married: Zend Framework and Doctrine

Wednesday, 8:30, Room Salon 1Guilherme on Doctrine 2!

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

Page 105: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 106: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 107: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 108: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 109: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 110: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL

I PDO API (ezcDatabase)

I Currently Support for MySql, PgSql,

Oracle, Sqlite, IBM and PDO Db2

I SqlSrv (+PDO) under development

I Lots of Convenience Methods (Zend Db)

I Currently planned: A Query Object

(Zend Db Select, ezcDatabaseQuery)

I SQL DDL and Data-QL abstraction (PEAR

MDB2 and ezcDatabaseSchema)

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

Page 111: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL Schema

I An OO-Approach to Database Schema

I Vendor independent abstraction of Tables,

Indexes, ForeignKeys and Sequences

I Get required set-up or tear-down SQL

I Get SQL to move from one to another

schema

I Doctrine Migrations

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

Page 112: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL Schema

I An OO-Approach to Database Schema

I Vendor independent abstraction of Tables,

Indexes, ForeignKeys and Sequences

I Get required set-up or tear-down SQL

I Get SQL to move from one to another

schema

I Doctrine Migrations

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

Page 113: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL Schema

I An OO-Approach to Database Schema

I Vendor independent abstraction of Tables,

Indexes, ForeignKeys and Sequences

I Get required set-up or tear-down SQL

I Get SQL to move from one to another

schema

I Doctrine Migrations

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

Page 114: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL Schema

I An OO-Approach to Database Schema

I Vendor independent abstraction of Tables,

Indexes, ForeignKeys and Sequences

I Get required set-up or tear-down SQL

I Get SQL to move from one to another

schema

I Doctrine Migrations

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

Page 115: Just Married: Zend Framework and Doctrine

Doctrine 2 DBAL Schema

I An OO-Approach to Database Schema

I Vendor independent abstraction of Tables,

Indexes, ForeignKeys and Sequences

I Get required set-up or tear-down SQL

I Get SQL to move from one to another

schema

I Doctrine Migrations

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

Page 116: Just Married: Zend Framework and Doctrine

ZF 2 with Doctrine DBAL 2

I First class support?

I Doctrine 2 DBAL API compatible with

Zend Db?

I Zend Db Select drop-in replacement?

I Table-, Row-Data-Gateway?

I ORM Integration?

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

Page 117: Just Married: Zend Framework and Doctrine

ZF 2 with Doctrine DBAL 2

I First class support?

I Doctrine 2 DBAL API compatible with

Zend Db?

I Zend Db Select drop-in replacement?

I Table-, Row-Data-Gateway?

I ORM Integration?

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

Page 118: Just Married: Zend Framework and Doctrine

ZF 2 with Doctrine DBAL 2

I First class support?

I Doctrine 2 DBAL API compatible with

Zend Db?

I Zend Db Select drop-in replacement?

I Table-, Row-Data-Gateway?

I ORM Integration?

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

Page 119: Just Married: Zend Framework and Doctrine

ZF 2 with Doctrine DBAL 2

I First class support?

I Doctrine 2 DBAL API compatible with

Zend Db?

I Zend Db Select drop-in replacement?

I Table-, Row-Data-Gateway?

I ORM Integration?

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

Page 120: Just Married: Zend Framework and Doctrine

ZF 2 with Doctrine DBAL 2

I First class support?

I Doctrine 2 DBAL API compatible with

Zend Db?

I Zend Db Select drop-in replacement?

I Table-, Row-Data-Gateway?

I ORM Integration?

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

Page 121: Just Married: Zend Framework and Doctrine

Questions?

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

Page 122: Just Married: Zend Framework and Doctrine

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