Symfony2 meets propel 1.5
Upcoming SlideShare
Loading in...5
×
 

Symfony2 meets propel 1.5

on

  • 16,819 views

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.

Statistics

Views

Total Views
16,819
Views on SlideShare
14,113
Embed Views
2,706

Actions

Likes
13
Downloads
82
Comments
3

25 Embeds 2,706

http://www.symfony.es 581
http://romain.cambien.net 491
http://propel.posterous.com 388
http://www.symfonylab.com 348
http://symfony.com 324
http://www.symfony-project.org 283
http://swik.net 115
http://www.symfony.gr.jp 98
http://rcambien.tumblr.com 16
http://www.sfexception.com 11
http://translate.googleusercontent.com 8
http://static.slidesharecdn.com 8
http://rimzy.net 6
http://www.pearltrees.com 6
http://symfony2developer.com 4
http://webcache.googleusercontent.com 4
http://feeds.feedburner.com 3
http://www.phpframeworks.com 3
http://ipv6.symfony2developer.com 2
http://www.prestataire-symfony.com 2
http://symfony.lab216.com 1
http://twiki.bestofmedia.com 1
https://klti.de 1
https://twitter.com 1
http://www.slideshare.net 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • 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.
    Are you sure you want to
    Your message goes here
    Processing…
  • It's defined as downloadable in the slideshare settings. I suppose it's a bug if the button doesn't appear.
    Are you sure you want to
    Your message goes here
    Processing…
  • make it downloadable please. offline reading is beautiful
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Symfony2 meets propel 1.5 Symfony2 meets propel 1.5 Presentation Transcript

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