Your SlideShare is downloading. ×
0
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Symfony2 meets propel 1.5
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Symfony2 meets propel 1.5

15,417

Published on

How does Propel 1.5 integrate inside the Symfony2 framework? All the details about the PropelBundle installation, usage, and development.

How does Propel 1.5 integrate inside the Symfony2 framework? All the details about the PropelBundle installation, usage, and development.

Published in: Technology, Design
3 Comments
13 Likes
Statistics
Notes
  • The 'allow download' setting was ticked, but somehow SlideShare didn't allow it. I unticked it and then reticked it again, and now it seems to work.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • It's defined as downloadable in the slideshare settings. I suppose it's a bug if the button doesn't appear.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • make it downloadable please. offline reading is beautiful
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
15,417
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
83
Comments
3
Likes
13
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Symfony 2 meets Propel 1.5François Zaninotto<br />
  • 2. François Zaninotto<br />Head of the Web Development Team at eTF1, editor the web properties of the leading TV network in France.<br />Former symfony 1 contributor<br />Author of “The Definitive Guide to Symfony” (APress)<br />Lead Developer of Propel since October, 2009<br />Interests: Web development, Usability, Agility, ROI<br />Not a developer<br />Twitter: @francoisz, Github: fzaninotto<br />
  • 3. Propel 1.5<br />
  • 4. No surprise<br />Backwards compatible with Propel 1.3 and 1.4<br />Faster than Propel 1.4, which was faster than Propel 1.3, which was...<br />Very IDE friendly<br />Better documented<br />More robust (3 times as many unit tests as Propel 1.3)<br />Fully integrated into symfony 1.3/1.4 (sfPropel15Plugin)<br />
  • 5. Surprise!<br />Major new features<br />Model Queries<br />Collections<br />Many-to-many relationships<br />Major new behaviors<br />Nested Sets<br />Concrete Table Inheritance<br />Better Oracle Support<br />
  • 6. Surprise!<br />Major new features<br />Model Queries<br />Collections<br />Many-to-many relationships<br />Major new behaviors<br />Nested Sets<br />Concrete Table Inheritance<br />Better Oracle Support<br />Killer Feature<br />Killer Feature<br />
  • 7. Model Queries<br />Model Queries are to the SQL query what ActiveRecord is to the table row<br />Shift from the relational Paradigm to the Object paradigm in Queries<br />Inspirations: SQL Alchemy, Doctrine, DbFinder, Arel<br />Code generation makes it fast and IDE friendly<br />Easy to learn and use<br />MUCH cleaner custom model code<br />Bye bye, Criteria!<br />
  • 8. Model Queries<br />$books = BookQuery::create()<br />->filterByPublishedAt(array(<br /> ‘max’ => time()<br /> ))<br />->filterByPublisher($publisher)<br />->useAuthorQuery()<br />->stillAlive()<br /> ->endUse()<br />->orderByTitle()<br />->find();<br />
  • 9. Concrete Table Inheritance<br />content<br />id<br />title<br />article<br />body<br />video<br />url<br />structure<br />data<br />
  • 10. Concrete Table Inheritance: An Example<br />$article = new Article();<br />$article->setTitle(‘France loses World Cup’);<br />$article->setBody(‘Lorem Ipsum’);<br />$article->save();<br />$video = new Video();<br />$video->setTitle(‘World Cup Goals’);<br />$video->setUrl(‘http://www.youtube.com/xxx’);<br />$video->save();<br />
  • 11. > SELECT * FROMarticle;<br />+----+------------------------+-------------+<br />| id | title | body |<br />+----+------------------------+-------------+<br />| 1 | France loses World Cup | Lorem Ipsum |<br />+----+------------------------+-------------+<br />> SELECT * FROMvideo;<br />+----+-----------------+----------------------------+<br />| id | title | url |<br />+----+-----------------+----------------------------+<br />| 2 | World Cup goals | http://www.youtube.com/xxx |<br />+----+-----------------+----------------------------+<br />> SELECT * FROM content;<br />+----+------------------------+<br />| id | title |<br />+----+------------------------+<br />| 1 | France loses World Cup |<br />| 2 | World Cup goals |<br />+----+------------------------+<br />
  • 12. Design your model in a true object-oriented way<br />Let Propel do the mapping with the relational world<br />Denormalize with ease for optimal performance<br />Let PHP manipulate inheritance, not data replication.<br />… Let PHP manipulate objects, not records.<br />… Let PHP manipulate collections, not arrays.<br />… Let PHP manipulate relations, not foreign keys.<br />
  • 13. Continuousimprovementsthroughminor versions<br />1.5.1<br />PropelObjectCollection::toKeyValue()<br />One-to-manyjoinedhydration (no LIMIT support)<br />CLI enhancements<br />1.5.2<br />Namespaces ! <br />ModelQuery::findOneOrCreate()<br />aggregate_columnbehavior<br />SQL Comments<br />
  • 14. Continuous improvements through minor versions<br />1.5.1<br />PropelObjectCollection::toKeyValue()<br />One-to-many joined hydration (no LIMIT support)<br />CLI enhancements<br />1.5.2<br />Namespaces ! <br />ModelQuery::findOneOrCreate()<br />aggregate_column behavior<br />SQL Comments<br />Must Have<br />Killer Feature<br />
  • 15. Namespaces<br />// in schema.xml<br /><table name="book"namespace="Bookstore"><br /> ...<br /></table><br />// in application code<br />useBookstoreBookQuery;<br />$book = BookQuery::create();<br />->findOneByTitle(‘War And Peace’);<br />echoget_class($book); // BookstoreBook<br />$author = $book->getAuthor();<br />echoget_class($author); // BookstorePeopleAuthor<br />
  • 16. Aggregate Table Behavior<br />author<br />id<br />name<br />book<br />id<br />title<br />author_id<br />*<br /><table name="author"><br /> <behavior name="aggregate_column"><br /><parameter name="name" value="nb_books" /><br /> <parameter name="foreign_table" value="book" /><br /> <parameter name="expression" value="COUNT(id)" /><br /> </behavior><br /> ...<br /></table><br />
  • 17. Aggregate Table Behavior<br />author<br />id<br />name<br />nb_books<br />book<br />id<br />title<br />author_id<br />*<br /><table name="author"><br /> <behavior name="aggregate_column"><br /><parameter name="name" value="nb_books" /><br /> <parameter name="foreign_table" value="book" /><br /> <parameter name="expression" value="COUNT(id)" /><br /> </behavior><br /> ...<br /></table><br />
  • 18. Aggregate Table Behavior<br />$author = new Author();<br />$author->setName(‘Leo Tolstoi');<br />$author->save();<br />echo $author->getNbBooks(); // 0<br />$book = new Book();<br />$book->setTitle(‘War and Peace’);<br />$book->setAuthor($author);<br />$book->save();<br />echo $author->getNbBooks(); // 1<br />$book->delete();<br />echo $author->getNbBooks(); // 0<br />
  • 19. No, really, Propel is definitely NOT DEAD<br />
  • 20. Propel 1.5 and Symfony<br />
  • 21. Propel Integration with symfony 1: sfPropel15Plugin<br /> Use sf configuration system (databases.yml, propel.ini)<br /> Use sf autoloading rather than Propel’s<br /> Use sf task system (and hides Phing, thank God)<br /> Adapt Propel to SF applications directory structure<br /><ul><li>YAML format for the schema (and plugin override)
  • 22. Web Debug Toolbar panel</li></ul> Form integration (Widgets, Validators, Model forms)<br /><ul><li>Admin Generator Theme</li></ul> Routing integration (Model routes, Model route collections)<br /><ul><li> Symfony Behaviors</li></li></ul><li>Propel Integration with Symfony2: PropelBundle<br /> Use sf configuration system (config.yml, Dependency Injection)<br /> Use sf autoloading rather than Propel’s (thanks Namespaces)<br /> Use sf command system (and hides Phing, thank God)<br /> Adapt Propel to SF applications directory structure<br />YAML format for the schema (and bundle override)<br />Web Debug Toolbar Panel<br /> Form integration (Widgets, Validators, Model forms)<br /> Admin Generator Theme<br />Routing integration (Model routes, Model route collections)<br /> Symfony Behaviors<br />
  • 23. Many of the symfony add-ons to Propel are now part of Propel 1.5<br />Model hooks, query hooks<br />Behavior system (at buildtime, for better performance and power)<br />auto_add_pkbehavior<br />timestampable behavior<br />isPrimaryString column attribute for automated __toString()<br />No need for custom symfony code for these<br />
  • 24. Why you may want to use Propel rather than Doctrine 2<br />No need to upgrade your Model code<br />It’s fast (without any cache system - that’s code generation)<br />It’s an ActiveRecord implementation<br />It has behaviors<br />It’s IDE friendly<br />The model code is easy to understand and debug<br />It has unique features (ModelQueries, concrete table inheritance, aggregate column behavior, etc.) <br />It’s robust (3000+ unit tests) and already used by many developers<br />It’s not alpha, it’s not beta, it’s already stable<br />
  • 25. Installation<br />
  • 26. The PropelBundle is bundled with the Symfony2 Framework<br />Register the bundle in the kernel<br />// in hello/HelloKernel.php<br />classHelloKernelextendsKernel<br />{<br />public functionregisterBundles()<br /> {<br /> $bundles = array(<br /> ...<br /> new SymfonyFrameworkPropelBundleBundle(),<br /> );<br />return $bundles;<br /> }<br />}<br />
  • 27. Add Propel and Phing libraries in src/vendor/<br />> cd src/vendor<br />> svn co http://svn.propelorm.org/branches/1.5/ propel<br />> svn co http://svn.phing.info/tags/2.3.3 phing<br />Add Propel and Phing paths to the project configuration<br /># in hello/config/config.yml<br />propel.config:<br />path: %kernel.root_dir%/../src/vendor/propel<br />phing_path: %kernel.root_dir%/../src/vendor/phing<br />
  • 28. Test the installation by calling the project console<br />> hello/console<br />Symfony version 2.0.0-DEV - hello<br />Usage:<br /> [options] command [arguments]<br />propel<br />:build Hub for Propel build commands (model, sql)<br />:build-model Build the Propel Object Model classes <br /> based on XML schemas<br />:build-sql Build the SQL generation code for all <br /> tables based on Propel XML schemas<br />
  • 29. Usage<br />
  • 30. Create an XML schema using namespaces<br />// in src/Application/HelloBundle/Resources/config/schema.xml<br /><?xml version="1.0" encoding="UTF-8"?><br /><database name="default" namespace="ApplicationHelloBundleModel" defaultIdMethod="native"><br /> <table name="book"><br /> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /><br /> <column name="title" type="varchar" primaryString="1" size="100" /><br /> <column name="ISBN" type="varchar" size="20" /><br /> <column name="author_id" type="integer" /><br /> <foreign-key foreignTable="author"><br /> <reference local="author_id" foreign="id" /><br /> </foreign-key><br /> </table><br /> <table name="author"><br /> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /><br /> <column name="first_name" type="varchar" size="100" /><br /> <column name="last_name" type="varchar" size="100" /><br /> </table><br /></database><br />
  • 31. Create an XML schemas using namespaces<br />// in src/Application/HelloBundle/Resources/config/schema.xml<br /><?xml version="1.0" encoding="UTF-8"?><br /><database name="default" namespace="ApplicationHelloBundleModel" defaultIdMethod="native"><br /> <table name="book"><br /> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /><br /> <column name="title" type="varchar" primaryString="1" size="100" /><br /> <column name="ISBN" type="varchar" size="20" /><br /> <column name="author_id" type="integer" /><br /> <foreign-key foreignTable="author"><br /> <reference local="author_id" foreign="id" /><br /> </foreign-key><br /> </table><br /> <table name="author"><br /> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /><br /> <column name="first_name" type="varchar" size="100" /><br /> <column name="last_name" type="varchar" size="100" /><br /> </table><br /></database><br />
  • 32. Build the model and SQL code<br />> cd sandbox<br />> hello/console propel:build<br />src/Application/HelloBundle/<br /> Model/<br /> map/<br /> om/<br /> Author.php<br /> AuthorPeer.php<br /> AuthorQuery.php<br /> Book.php<br /> BookPeer.php<br /> BookQuery.php<br />hello/propel/sql/<br /> HelloBundle-schema.sql<br />
  • 33. // in sandbox/src/application/HelloBundle/Model/Book.php<br />namespaceApplicationHelloBundleModel;<br />useApplicationHelloBundleModelOmBaseBook;<br />/**<br /> * Skeleton subclass for representing a row from the <br /> * 'book' table.<br /> *<br /> * You should add additional methods to this class to meet<br /> * the application requirements. This class will only be<br /> * generated as long as it does not already exist in the<br /> * output directory.<br /> */<br />classBookextendsBaseBook {<br />} // Book<br />
  • 34. Setup your connection in the project configuration<br /># in sandbox/hello/config/config.yml<br />propel.dbal:<br />driver: mysql<br />user: root<br />password: null<br />dsn: mysql:host=localhost;dbname=test<br /> options: {}<br />
  • 35. Use models in your actions as with Propel 1.5 alone<br />Symfony handles the autoloading<br />// in sandbox/src/Application/HelloBundle/Controller/HelloController.php<br />namespaceApplicationHelloBundleController;<br />useSymfonyFrameworkWebBundleController;<br />useApplicationHelloBundleModelAuthorQuery;<br />classHelloControllerextendsController<br />{<br />public functionindexAction($name)<br /> {<br /> $author = AuthorQuery::create()<br /> ->findOneByName($name);<br />return $this->render('HelloBundle:Hello:index', <br />array('author' => $author));<br /> }<br />}<br />
  • 36. That’s about it<br />All the Propel features are ready to use… in the Propel way<br />
  • 37. The Future of Propel 1.5 and Symfony2<br />
  • 38. Ask Fabien<br />
  • 39. A lot left to do<br />YAML format for the schema (and bundle override)<br />Web Debug Toolbar Panel<br />Form integration (Widgets, Validators, Model forms)<br />Admin Generator Theme<br />Documentation<br />Unit tests<br />
  • 40. And even more<br />Embedded Relation Forms<br />Admin generator on steroids<br />Easy Custom Filter<br />Cross-module links<br />Plain text fields<br />Advanced Object Routing<br />Collection routes<br />Nested routes<br />A thousand more ideas worth implementing<br />cf. sfPropel15Plugin<br />cf. DbFinderPlugin<br />
  • 41. Not much time to do so<br />I’m already developing Propel<br />I’m already developing sfPropel15Plugin<br />I also have a full-time job<br />…and a family<br />Any help is welcome!<br />
  • 42. Questions?<br />Online Resources<br />http://github.com/fzaninotto/symfony<br />http://www.propelorm.org/<br />http://www.symfony-project.org/plugins/sfPropel15Plugin<br />News about all that<br />http://propel.posterous.com/<br />http://twitter.com/francoisz<br />

×