View
8.327
Download
2
Category
Tags:
Preview:
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
I Records
I Base Records
I Tables
Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 23 / 55
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
A Simple Form: Tweaking
Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 32 / 55
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
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
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
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
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
Advanced Forms: Relations
Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 37 / 55
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
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
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
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
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
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
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
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
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
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
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
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
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
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
<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
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
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
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
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
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
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
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
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
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
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
Wednesday, 8:30, Room Salon 1Guilherme on Doctrine 2!
Eberlei (direkt effekt GmbH) ZF and Doctrine 1 IPC Spring 2010 50 / 55
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Recommended