SlideShare ist ein Scribd-Unternehmen logo
1 von 44
Downloaden Sie, um offline zu lesen
Doctrine, PHP Object
 Relational Mapper


Doctrine   1   http://www.doctrine-project.org
What is Doctrine?
‣ Doctrine is a Object Relational Mapper built
  to work with PHP 5.2.3 or greater.

‣ Primarily based off of Java Hibernate
‣ Influenced by Ruby on Rails ActiveRecord

From WikiPedia: http://en.wikipedia.org/wiki/Object-
relational_mapping


Doctrine                  2               http://www.doctrine-project.org
The Layers




Doctrine       3        http://www.doctrine-project.org
Why should I use it?

 ‣ Makes difficult problems easy
                                Because
                               jwage said

 ‣ Saves money                    so!!!




 ‣ I like money


Doctrine          4       http://www.doctrine-project.org
Will it solve world hunger?

‣ No
‣ Will not solve all your problems
‣ Helps more than it hurts


Doctrine         5           http://www.doctrine-project.org
1, 2, 3, Let’s go!


Doctrine   6   http://www.doctrine-project.org
Doctrine   7   http://www.doctrine-project.org
Doctrine   8   http://www.doctrine-project.org
Doctrine   9   http://www.doctrine-project.org
The examples in the next slides use the following models




Doctrine                   10               http://www.doctrine-project.org
Doctrine Query Language
    A object-oriented SQL-dialect used for retrieving data


‣ DQL makes complex SQL simple
‣ Brings OOP to your database queries
‣ Parsed and converted to SQL for your
  dbms

‣ DQL parsing is cached
Doctrine                      11                   http://www.doctrine-project.org
DQL makes complex SQL simple



The DQL: FROM BlogPost p INNER JOIN p.Author a LEFT JOIN p.Tags t

The Resulting SQL: SELECT b.id AS b__id, b.title AS b__title, b.body AS
b__body, b.author_id AS b__author_id, b.slug AS b__slug, b.created_at AS
b__created_at, b.updated_at AS b__updated_at, a.id AS a__id, a.name AS
a__name, t.id AS t__id, t.name AS t__name FROM blog_post b INNER JOIN
author a ON b.author_id = a.id LEFT JOIN blog_post_tag b2 ON b.id =
b2.blog_post_id LEFT JOIN tag t ON t.id = b2.tag_id

       Special select aliases created so Doctrine can hydrate the data


   Doctrine                          12                    http://www.doctrine-project.org
Let Doctrine do the work

‣ You don’t need to know how things are
  related, just that they are.

‣ Uses relationship information to
  automatically fill in the blanks when
  building SQL.

‣ Write complex queries very fast and
  efficiently
Doctrine              13         http://www.doctrine-project.org
Executing the DQL
 Query Results
  Hydrated as
Multi-Dimensional
Array or Objects




Doctrine            14   http://www.doctrine-project.org
DBMS Functions
 ‣ DBMS functions passed through parser to SQL
 ‣ Any DBMS function can be used
 ‣ Propel short coming
 ‣ Can be used in WHERE, HAVING, etc.




Doctrine                 15             http://www.doctrine-project.org
Named Queries
 ‣ Create named queries
 ‣ Execute named queries
 ‣ Retrieve named query objects




Doctrine            16            http://www.doctrine-project.org
Working with
       Objects


Doctrine   17   http://www.doctrine-project.org
Accessors/Mutators
 ‣ 3 Different Styles
 ‣ Easy to use




Doctrine         18     http://www.doctrine-project.org
Overriding
‣ Override accessors and mutators easily
‣ Functions recognized and invoked with normal accessors
‣ Use _get()/_set() to avoid infinite loop




Doctrine                       19                 http://www.doctrine-project.org
Hydration Modes
 ‣ As objects
 ‣ As php arrays
 ‣ No hydration


Doctrine          20   http://www.doctrine-project.org
Array Access
              Recommended
‣ Works with both
   record and array
   hydration methods

‣ Write code to
   work with objects
   and switch to
   array hydration
   without changing
   code

‣ Performance
‣ Most familiar
    Doctrine           21   http://www.doctrine-project.org
Simple Relationships

‣ Relations work the way
   you’d expect it to

‣ Several different
   relationship types
   supported

‣ Specify relationships
   inline




   Doctrine                22   http://www.doctrine-project.org
Working with m2m


‣ Easy to link and unlink
‣ Specify new objects
   inline

‣ Attach existing objects




   Doctrine                 23   http://www.doctrine-project.org
Updating

‣ Retrieve and update
‣ Update with one DQL
   query

‣ DQL updates don’t issue
   events/hooks for
   updating




    Doctrine                24     http://www.doctrine-project.org
Deleting
‣ Retrieve and
  delete

‣ Delete without
  retrieving

‣ DQL deletes
  issue individual
  queries



   Doctrine             25      http://www.doctrine-project.org
Many2Many

‣ Reference table is used transparently
‣ No need to manually join reference table
‣ Easy to store extra data with reference
  tables



Doctrine             26          http://www.doctrine-project.org
Many2Many Example 1




Doctrine   27   http://www.doctrine-project.org
Many2Many Example 2
           Simplified even more




Doctrine           28            http://www.doctrine-project.org
Friends List with Equal m2m




Doctrine     29     http://www.doctrine-project.org
Inspecting SQL of Equal M2M




       SQL is generated with OR condition
       so that relationship data is returned
       on both sides




 Doctrine                 30               http://www.doctrine-project.org
Friends/Buddy List
Different SQL used so objects
which exist on one side, exist
automatically on the other




        Now Fabien and I are friends!! Too easy!
Doctrine                   31               http://www.doctrine-project.org
Plug n’ Play Behaviors
 ‣ Extract functionality
 ‣ Code re-usability
 ‣ Maintenance
 ‣ Time and money saver
 ‣ Write your own
 ‣ Offloads functionality to community
Doctrine               32        http://www.doctrine-project.org
Core Behaviors
 ‣ Timestampable
 ‣ Sluggable
 ‣ Versionable
 ‣ I18n
 ‣ SoftDelete
 ‣ NestedSet
 ‣ Geographical
Doctrine      33   http://www.doctrine-project.org
Real world example
   Using the Sluggable and Timestampable behaviors for a BlogPost model




Doctrine                            34                      http://www.doctrine-project.org
The Create Table SQL




Doctrine   35   http://www.doctrine-project.org
Behavior In Action




Doctrine   36     http://www.doctrine-project.org
The Results


                     Set automatically!




                     Updated!



Doctrine        37         http://www.doctrine-project.org
What Happened?
‣ Columns automatically added
‣ Automatically sets created_at and
    update_at timestamps on save
‣   Automatic creation of unique, human
    readable record identifier(slug)

FREE SOFTWARE! FREE FUNCTIONALITY!
         ARE YOU SERIOUS?


Doctrine             38          http://www.doctrine-project.org
Data Fixtures

‣ Easy to specify
  m2m data

‣ We did it first,
  not rails ;)




 Doctrine           39   http://www.doctrine-project.org
Data Fixtures Inline

‣ Specify data
  fixtures inline

‣ More readable
‣ If a relationship
  exists, you can
  populate it inline


  Doctrine             40   http://www.doctrine-project.org
Future
‣ Doctrine 1.1, 1.2.....2.0
‣ Separate packages for DBAL and ORM
‣ PEAR2: Replace MDB2? Defacto standard for
  DBAL and ORM in PHP?

‣ Integration with many other libraries: symfony,
  Zend Framework, Code Igniter, Typo3, etc.

  Doctrine                    41       http://www.doctrine-project.org
Doctrine 2.0

‣ Almost entirely rewritten code base
‣ Decoupling of components
‣ Off-loading of features to community: behaviors,
  validation, yaml schema files, data fixtures, etc.

‣ Concentrate more on ORM specific functionality

  Doctrine               42             http://www.doctrine-project.org
Want more?
‣ Read More
  ‣ http://www.doctrine-project.org/documentation/manual/1_0/?one-page#dql-
      doctrine-query-language
  ‣   http://www.doctrine-project.org/documentation/manual/1_0/?one-page#migration
  ‣   http://www.doctrine-project.org/documentation/manual/1_0/?one-page#behaviors

‣ Community - http://www.doctrine-project.org/community
‣ Frequently Asked Questions - http://www.doctrine-project.org/faq
‣ About Doctrine - http://www.doctrine-project.org/about
‣ The Doctrine Blog - http://www.doctrine-project.org/blog
‣ Documentation - http://www.doctrine-project.org/documentation



  Doctrine                                43                         http://www.doctrine-project.org
THE END!
I hope this presentation was helpful and sparked some
             interest to play with Doctrine!




              Follow the Doctrine...



Doctrine                 44              http://www.doctrine-project.org

Weitere ähnliche Inhalte

Was ist angesagt?

Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
Christine Cheung
 
Plain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticalsPlain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticals
Angela Byron
 
Perl%20Tutorial.!Picking%20Up%20Perl
Perl%20Tutorial.!Picking%20Up%20PerlPerl%20Tutorial.!Picking%20Up%20Perl
Perl%20Tutorial.!Picking%20Up%20Perl
tutorialsruby
 

Was ist angesagt? (18)

Validating Big Data Pipelines - Big Data Spain 2018
Validating Big Data Pipelines - Big Data Spain 2018Validating Big Data Pipelines - Big Data Spain 2018
Validating Big Data Pipelines - Big Data Spain 2018
 
Aligning Ember.js with Web Standards
Aligning Ember.js with Web StandardsAligning Ember.js with Web Standards
Aligning Ember.js with Web Standards
 
Validating spark ml jobs stopping failures before production on Apache Spark ...
Validating spark ml jobs stopping failures before production on Apache Spark ...Validating spark ml jobs stopping failures before production on Apache Spark ...
Validating spark ml jobs stopping failures before production on Apache Spark ...
 
Refactoring legacy code guided by tests in WordPress
Refactoring legacy code guided by tests in WordPressRefactoring legacy code guided by tests in WordPress
Refactoring legacy code guided by tests in WordPress
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Best Practices for Front-End Django Developers
Best Practices for Front-End Django DevelopersBest Practices for Front-End Django Developers
Best Practices for Front-End Django Developers
 
Ugo Cei Presentation
Ugo Cei PresentationUgo Cei Presentation
Ugo Cei Presentation
 
Plain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticalsPlain english guide to drupal 8 criticals
Plain english guide to drupal 8 criticals
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
Drupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surfaceDrupal 6.x, Drupal 7.x -- Scratching the surface
Drupal 6.x, Drupal 7.x -- Scratching the surface
 
Migrate to Drupal 8
Migrate to Drupal 8Migrate to Drupal 8
Migrate to Drupal 8
 
Perl%20Tutorial.!Picking%20Up%20Perl
Perl%20Tutorial.!Picking%20Up%20PerlPerl%20Tutorial.!Picking%20Up%20Perl
Perl%20Tutorial.!Picking%20Up%20Perl
 
Java presentation
Java presentationJava presentation
Java presentation
 
.NET @ apache.org
 .NET @ apache.org .NET @ apache.org
.NET @ apache.org
 
Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)Future of Java EE with SE 8 (revised)
Future of Java EE with SE 8 (revised)
 
features+
features+features+
features+
 
Introducing RaveJS: Spring Boot concepts for JavaScript applications
Introducing RaveJS: Spring Boot concepts for JavaScript applicationsIntroducing RaveJS: Spring Boot concepts for JavaScript applications
Introducing RaveJS: Spring Boot concepts for JavaScript applications
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 

Ähnlich wie Doctrine Php Object Relational Mapper

Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
Shekhar Gulati
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
cNguyn506241
 
Drupal and the semantic web - SemTechBiz 2012
Drupal and the semantic web - SemTechBiz 2012Drupal and the semantic web - SemTechBiz 2012
Drupal and the semantic web - SemTechBiz 2012
scorlosquet
 

Ähnlich wie Doctrine Php Object Relational Mapper (20)

Doctrine Project
Doctrine ProjectDoctrine Project
Doctrine Project
 
Extracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails AppsExtracting Plugins And Gems From Rails Apps
Extracting Plugins And Gems From Rails Apps
 
ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!ICONUK 2015 - Gradle Up!
ICONUK 2015 - Gradle Up!
 
Rebuilding our Foundation
Rebuilding our FoundationRebuilding our Foundation
Rebuilding our Foundation
 
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of SzegedLecture 8 - Qooxdoo - Rap Course At The University Of Szeged
Lecture 8 - Qooxdoo - Rap Course At The University Of Szeged
 
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdfAstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
AstroLabs_Academy_Learning_to_Code-Coding_Bootcamp_Day1.pdf
 
Spark tutorial
Spark tutorialSpark tutorial
Spark tutorial
 
Play framework 2 : Peter Hilton
Play framework 2 : Peter HiltonPlay framework 2 : Peter Hilton
Play framework 2 : Peter Hilton
 
AzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр ШевнинAzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
AzovDevMeetup 2016 | Angular 2: обзор | Александр Шевнин
 
Building Reactive webapp with React/Flux
Building Reactive webapp with React/FluxBuilding Reactive webapp with React/Flux
Building Reactive webapp with React/Flux
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 
Data ops in practice - Swedish style
Data ops in practice - Swedish styleData ops in practice - Swedish style
Data ops in practice - Swedish style
 
Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud Java(ee) mongo db applications in the cloud
Java(ee) mongo db applications in the cloud
 
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
49.INS2065.Computer Based Technologies.TA.NguyenDucAnh.pdf
 
Prg 421 guide focus dreams prg421guide.com
Prg 421 guide focus dreams   prg421guide.comPrg 421 guide focus dreams   prg421guide.com
Prg 421 guide focus dreams prg421guide.com
 
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal StackDecoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
Decoupling Drupal mit dem Lupus Nuxt.js Drupal Stack
 
Super powered Drupal development with docker
Super powered Drupal development with dockerSuper powered Drupal development with docker
Super powered Drupal development with docker
 
Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!Catalyst - refactor large apps with it and have fun!
Catalyst - refactor large apps with it and have fun!
 
Drupal and the semantic web - SemTechBiz 2012
Drupal and the semantic web - SemTechBiz 2012Drupal and the semantic web - SemTechBiz 2012
Drupal and the semantic web - SemTechBiz 2012
 
ArangoDB
ArangoDBArangoDB
ArangoDB
 

Mehr von Jonathan Wage

OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky Infrastructure
Jonathan Wage
 
Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 Paris
Jonathan Wage
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
Jonathan Wage
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
Jonathan Wage
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
 
Sympal A Cmf Based On Symfony
Sympal   A Cmf Based On SymfonySympal   A Cmf Based On Symfony
Sympal A Cmf Based On Symfony
Jonathan Wage
 

Mehr von Jonathan Wage (20)

Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky Infrastructure
 
Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 Paris
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
 
Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
Libertyvasion2010
Libertyvasion2010Libertyvasion2010
Libertyvasion2010
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Doctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPDoctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHP
 
Introduction To Doctrine 2
Introduction To Doctrine 2Introduction To Doctrine 2
Introduction To Doctrine 2
 
Doctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php OrmDoctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php Orm
 
Doctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHPDoctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHP
 
Sympal A Cmf Based On Symfony
Sympal   A Cmf Based On SymfonySympal   A Cmf Based On Symfony
Sympal A Cmf Based On Symfony
 
Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2
 
Sympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSSympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMS
 
What's new in Doctrine
What's new in DoctrineWhat's new in Doctrine
What's new in Doctrine
 
What Is Doctrine?
What Is Doctrine?What Is Doctrine?
What Is Doctrine?
 

Doctrine Php Object Relational Mapper

  • 1. Doctrine, PHP Object Relational Mapper Doctrine 1 http://www.doctrine-project.org
  • 2. What is Doctrine? ‣ Doctrine is a Object Relational Mapper built to work with PHP 5.2.3 or greater. ‣ Primarily based off of Java Hibernate ‣ Influenced by Ruby on Rails ActiveRecord From WikiPedia: http://en.wikipedia.org/wiki/Object- relational_mapping Doctrine 2 http://www.doctrine-project.org
  • 3. The Layers Doctrine 3 http://www.doctrine-project.org
  • 4. Why should I use it? ‣ Makes difficult problems easy Because jwage said ‣ Saves money so!!! ‣ I like money Doctrine 4 http://www.doctrine-project.org
  • 5. Will it solve world hunger? ‣ No ‣ Will not solve all your problems ‣ Helps more than it hurts Doctrine 5 http://www.doctrine-project.org
  • 6. 1, 2, 3, Let’s go! Doctrine 6 http://www.doctrine-project.org
  • 7. Doctrine 7 http://www.doctrine-project.org
  • 8. Doctrine 8 http://www.doctrine-project.org
  • 9. Doctrine 9 http://www.doctrine-project.org
  • 10. The examples in the next slides use the following models Doctrine 10 http://www.doctrine-project.org
  • 11. Doctrine Query Language A object-oriented SQL-dialect used for retrieving data ‣ DQL makes complex SQL simple ‣ Brings OOP to your database queries ‣ Parsed and converted to SQL for your dbms ‣ DQL parsing is cached Doctrine 11 http://www.doctrine-project.org
  • 12. DQL makes complex SQL simple The DQL: FROM BlogPost p INNER JOIN p.Author a LEFT JOIN p.Tags t The Resulting SQL: SELECT b.id AS b__id, b.title AS b__title, b.body AS b__body, b.author_id AS b__author_id, b.slug AS b__slug, b.created_at AS b__created_at, b.updated_at AS b__updated_at, a.id AS a__id, a.name AS a__name, t.id AS t__id, t.name AS t__name FROM blog_post b INNER JOIN author a ON b.author_id = a.id LEFT JOIN blog_post_tag b2 ON b.id = b2.blog_post_id LEFT JOIN tag t ON t.id = b2.tag_id Special select aliases created so Doctrine can hydrate the data Doctrine 12 http://www.doctrine-project.org
  • 13. Let Doctrine do the work ‣ You don’t need to know how things are related, just that they are. ‣ Uses relationship information to automatically fill in the blanks when building SQL. ‣ Write complex queries very fast and efficiently Doctrine 13 http://www.doctrine-project.org
  • 14. Executing the DQL Query Results Hydrated as Multi-Dimensional Array or Objects Doctrine 14 http://www.doctrine-project.org
  • 15. DBMS Functions ‣ DBMS functions passed through parser to SQL ‣ Any DBMS function can be used ‣ Propel short coming ‣ Can be used in WHERE, HAVING, etc. Doctrine 15 http://www.doctrine-project.org
  • 16. Named Queries ‣ Create named queries ‣ Execute named queries ‣ Retrieve named query objects Doctrine 16 http://www.doctrine-project.org
  • 17. Working with Objects Doctrine 17 http://www.doctrine-project.org
  • 18. Accessors/Mutators ‣ 3 Different Styles ‣ Easy to use Doctrine 18 http://www.doctrine-project.org
  • 19. Overriding ‣ Override accessors and mutators easily ‣ Functions recognized and invoked with normal accessors ‣ Use _get()/_set() to avoid infinite loop Doctrine 19 http://www.doctrine-project.org
  • 20. Hydration Modes ‣ As objects ‣ As php arrays ‣ No hydration Doctrine 20 http://www.doctrine-project.org
  • 21. Array Access Recommended ‣ Works with both record and array hydration methods ‣ Write code to work with objects and switch to array hydration without changing code ‣ Performance ‣ Most familiar Doctrine 21 http://www.doctrine-project.org
  • 22. Simple Relationships ‣ Relations work the way you’d expect it to ‣ Several different relationship types supported ‣ Specify relationships inline Doctrine 22 http://www.doctrine-project.org
  • 23. Working with m2m ‣ Easy to link and unlink ‣ Specify new objects inline ‣ Attach existing objects Doctrine 23 http://www.doctrine-project.org
  • 24. Updating ‣ Retrieve and update ‣ Update with one DQL query ‣ DQL updates don’t issue events/hooks for updating Doctrine 24 http://www.doctrine-project.org
  • 25. Deleting ‣ Retrieve and delete ‣ Delete without retrieving ‣ DQL deletes issue individual queries Doctrine 25 http://www.doctrine-project.org
  • 26. Many2Many ‣ Reference table is used transparently ‣ No need to manually join reference table ‣ Easy to store extra data with reference tables Doctrine 26 http://www.doctrine-project.org
  • 27. Many2Many Example 1 Doctrine 27 http://www.doctrine-project.org
  • 28. Many2Many Example 2 Simplified even more Doctrine 28 http://www.doctrine-project.org
  • 29. Friends List with Equal m2m Doctrine 29 http://www.doctrine-project.org
  • 30. Inspecting SQL of Equal M2M SQL is generated with OR condition so that relationship data is returned on both sides Doctrine 30 http://www.doctrine-project.org
  • 31. Friends/Buddy List Different SQL used so objects which exist on one side, exist automatically on the other Now Fabien and I are friends!! Too easy! Doctrine 31 http://www.doctrine-project.org
  • 32. Plug n’ Play Behaviors ‣ Extract functionality ‣ Code re-usability ‣ Maintenance ‣ Time and money saver ‣ Write your own ‣ Offloads functionality to community Doctrine 32 http://www.doctrine-project.org
  • 33. Core Behaviors ‣ Timestampable ‣ Sluggable ‣ Versionable ‣ I18n ‣ SoftDelete ‣ NestedSet ‣ Geographical Doctrine 33 http://www.doctrine-project.org
  • 34. Real world example Using the Sluggable and Timestampable behaviors for a BlogPost model Doctrine 34 http://www.doctrine-project.org
  • 35. The Create Table SQL Doctrine 35 http://www.doctrine-project.org
  • 36. Behavior In Action Doctrine 36 http://www.doctrine-project.org
  • 37. The Results Set automatically! Updated! Doctrine 37 http://www.doctrine-project.org
  • 38. What Happened? ‣ Columns automatically added ‣ Automatically sets created_at and update_at timestamps on save ‣ Automatic creation of unique, human readable record identifier(slug) FREE SOFTWARE! FREE FUNCTIONALITY! ARE YOU SERIOUS? Doctrine 38 http://www.doctrine-project.org
  • 39. Data Fixtures ‣ Easy to specify m2m data ‣ We did it first, not rails ;) Doctrine 39 http://www.doctrine-project.org
  • 40. Data Fixtures Inline ‣ Specify data fixtures inline ‣ More readable ‣ If a relationship exists, you can populate it inline Doctrine 40 http://www.doctrine-project.org
  • 41. Future ‣ Doctrine 1.1, 1.2.....2.0 ‣ Separate packages for DBAL and ORM ‣ PEAR2: Replace MDB2? Defacto standard for DBAL and ORM in PHP? ‣ Integration with many other libraries: symfony, Zend Framework, Code Igniter, Typo3, etc. Doctrine 41 http://www.doctrine-project.org
  • 42. Doctrine 2.0 ‣ Almost entirely rewritten code base ‣ Decoupling of components ‣ Off-loading of features to community: behaviors, validation, yaml schema files, data fixtures, etc. ‣ Concentrate more on ORM specific functionality Doctrine 42 http://www.doctrine-project.org
  • 43. Want more? ‣ Read More ‣ http://www.doctrine-project.org/documentation/manual/1_0/?one-page#dql- doctrine-query-language ‣ http://www.doctrine-project.org/documentation/manual/1_0/?one-page#migration ‣ http://www.doctrine-project.org/documentation/manual/1_0/?one-page#behaviors ‣ Community - http://www.doctrine-project.org/community ‣ Frequently Asked Questions - http://www.doctrine-project.org/faq ‣ About Doctrine - http://www.doctrine-project.org/about ‣ The Doctrine Blog - http://www.doctrine-project.org/blog ‣ Documentation - http://www.doctrine-project.org/documentation Doctrine 43 http://www.doctrine-project.org
  • 44. THE END! I hope this presentation was helpful and sparked some interest to play with Doctrine! Follow the Doctrine... Doctrine 44 http://www.doctrine-project.org