<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://prendreuncafe.com/blog/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
  <title>Prendre un Café - Tag - doctrine</title>
  <link>http://prendreuncafe.com/blog/</link>
  <atom:link href="http://prendreuncafe.com/blog/feed/tag/doctrine/rss2" rel="self" type="application/rss+xml"/>
  <description></description>
  <language>fr</language>
  <pubDate>Thu, 20 Nov 2008 08:30:33 +0100</pubDate>
  <copyright>Contenus sous licence Creative Commons BY-SA</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Let's Play with Symfony 1.2 and Doctrine</title>
    <link>http://prendreuncafe.com/blog/post/2008/10/31/Playing-with-symfony-12-and-Doctrine</link>
    <guid isPermaLink="false">urn:md5:cc61c2ac96c03c39fa34e9aba66c4769</guid>
    <pubDate>Fri, 31 Oct 2008 11:00:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>doctrine</category><category>howto</category><category>php</category><category>symfony</category>    
    <description>    &lt;p&gt;It&amp;#8217;s been quite a long time I didn&amp;#8217;t give a go to &lt;a href=&quot;http://www.doctrine-project.org/&quot; hreflang=&quot;en&quot;&gt;Doctrine&lt;/a&gt;, so as &lt;a href=&quot;http://www.symfony-project.org/blog/2008/09/16/doctrine-gains-symfony-citizenship-in-1-2&quot; hreflang=&quot;en&quot;&gt;it&amp;#8217;s gonna be bundled by default in with the upcoming 1.2&lt;/a&gt; release of &lt;a href=&quot;http://www.symfony-project.org/&quot; hreflang=&quot;en&quot;&gt;symfony&lt;/a&gt;, I thought it was a good occasion to play with it.&lt;/p&gt;


&lt;p&gt;So let&amp;#8217;s checkout the &lt;a href=&quot;http://svn.symfony-project.com/branches/1.2/&quot; hreflang=&quot;en&quot;&gt;1.2 SVN branch of symfony&lt;/a&gt; and create a test project with a &lt;code&gt;main&lt;/code&gt; application&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/10/31/#pnote-999-1&quot; id=&quot;rev-pnote-999-1&quot;&gt;1&lt;/a&gt;]&lt;/sup&gt;:&lt;/p&gt;


&lt;pre&gt;$ mkdir sf12test &amp;amp;&amp;amp; cd sf12test
$ mkdir -p lib/vendor
$ svn co http://svn.symfony-project.com/branches/1.2 lib/vendor/symfony
$ php lib/vendor/symfony/data/bin/symfony generate:project sf12test
$ ln -s ../lib/vendor/symfony/data/web/sf web/sf
$ ./symfony generate:app main&lt;/pre&gt;


&lt;p&gt;Create a webserver vhost pointing to the &lt;code&gt;web&lt;/code&gt; folder of the project directory. I&amp;#8217;ve already explained &lt;a href=&quot;http://prendreuncafe.com/blog/?q=symfony+VirtualHost&quot;&gt;plenty of times&lt;/a&gt; how to achieve this step.&lt;/p&gt;


&lt;p&gt;Now, let&amp;#8217;s enable the &lt;code&gt;sfDoctrinePlugin&lt;/code&gt; and disable the Propel one by editing the &lt;code&gt;setup()&lt;/code&gt; method of the &lt;code&gt;config/ProjectConfiguration.class.php&lt;/code&gt; file:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; setup&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;disablePlugins&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'sfPropelPlugin'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;enablePlugins&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'sfDoctrinePlugin'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;You can list the available tasks running this simple command:&lt;/p&gt;


&lt;pre&gt;$ ./symfony list doctrine&lt;/pre&gt;


&lt;h3&gt;Managing the Database Schema&lt;/h3&gt;


&lt;p&gt;First, configure your &lt;code&gt;config/databases.yml&lt;/code&gt; file to set the database connection parameters. If you want to quick test Doctrine, use a local SQLite db, like this:&lt;/p&gt;

&lt;pre&gt;all:
  doctrine:
    class:    sfDoctrineDatabase
    param:
      dsn:    sqlite://&amp;lt;?php echo dirname(__FILE__).'/../data/data.db' ?&amp;gt;&lt;/pre&gt;


&lt;p&gt;We&amp;#8217;re going to make a very simple weblog application, so let&amp;#8217;s configure our database schema. We can do it in YAML&lt;sup&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/10/31/#pnote-999-2&quot; id=&quot;rev-pnote-999-2&quot;&gt;2&lt;/a&gt;]&lt;/sup&gt;, so fire up your favorite editor/IDE and edit a brand new &lt;code&gt;config/doctrine/schema.yml&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;BlogPost:
  actAs:
    Sluggable:
      fields:       [title]
    Timestampable:
  columns:
    title:          string(255)
    body:           clob
    author:         string(255)
&amp;nbsp;
BlogComment:
  actAs:            [Timestampable]
  columns:
    blog_post_id:   integer
    author:         string(255)
    email:          string(255)
    content:        clob
  relations:
    BlogPost:
      class:        BlogPost
      local:        blog_post_id
      foreign:      id
      foreignType:  many
      type:         one&lt;/pre&gt;


&lt;p&gt;Note that Doctrine offers several pretty cool features including native behaviors (&lt;em&gt;timestampable&lt;/em&gt; and &lt;em&gt;slugable&lt;/em&gt; are used here).&lt;/p&gt;


&lt;p&gt;Now, create a &lt;code&gt;data/fixtures&lt;/code&gt; folder and put a &lt;code&gt;data.yml&lt;/code&gt; file in, containing some test data in YAML format:&lt;/p&gt;

&lt;pre&gt;BlogPost:
  p1:
    title: My first post
    body: |
      This is cool.
    author: NiKo
    created_at: &amp;quot;&amp;lt;?php echo date('Y-m-d H:i:s', time() - 86400) ?&amp;gt;&amp;quot;
  p2:
    title: My second post
    body: |
      This is still cool.
    author: NiKo
    created_at: &amp;quot;&amp;lt;?php echo date('Y-m-d H:i:s', time() - 7200) ?&amp;gt;&amp;quot;
  p3:
    title: Third post
    body: |
      Is this one cool?
    author: Roger Hanin
    created_at: &amp;quot;&amp;lt;?php echo date('Y-m-d H:i:s') ?&amp;gt;&amp;quot;
&amp;nbsp;
BlogComment:
  c1:
    BlogPost: p3
    author: John
    email: john@doe.com
    content: Hey, you're right there.
    created_at: &amp;quot;&amp;lt;?php echo date('Y-m-d H:i:s', time() - 86400) ?&amp;gt;&amp;quot;
  c2:
    BlogPost: p3
    author: Paul
    email: paul@doe.com
    content: Nope, he's not.
    created_at: &amp;quot;&amp;lt;?php echo date('Y-m-d H:i:s') ?&amp;gt;&amp;quot;&lt;/pre&gt;


&lt;p&gt;Okay, now run the command below to generate the needed files, create the database and fill it with the data fixtures:&lt;/p&gt;


&lt;pre&gt;$ ./symfony doctrine:build-all-load&lt;/pre&gt;


&lt;p&gt;We can run several &lt;acronym title=&quot;Doctrine Query Language&quot;&gt;DQL&lt;/acronym&gt; queries in command line to check if everything is fine. DQL is very powerful, and compatible with a lot of RDBMS. You&amp;#8217;ll find &lt;a href=&quot;http://www.doctrine-project.org/documentation/manual/1_0?one-page#dql-doctrine-query-language&quot; hreflang=&quot;en&quot;&gt;more information on DQL on the doctrine website&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;For example, to find all blog posts:&lt;/p&gt;

&lt;pre&gt;
$ ./symfony doctrine:dql &amp;quot;From BlogPost p&amp;quot;
found 3 results
-
  id: '21'
  title: 'My first post'
  body: &amp;quot;This is cool.\n&amp;quot;
  author: NiKo
  slug: my-first-post
  created_at: '2008-10-29 15:14:25'
  updated_at: '2008-10-30 15:14:25'
-
  id: '22'
  title: 'My second post'
  body: &amp;quot;This is still cool.\n&amp;quot;
  author: NiKo
  slug: my-second-post
  created_at: '2008-10-30 13:14:25'
  updated_at: '2008-10-30 15:14:25'
-
  id: '23'
  title: 'Third post'
  body: &amp;quot;Is this one cool?\n&amp;quot;
  author: 'Roger Hanin'
  slug: third-post
  created_at: '2008-10-30 15:14:25'
  updated_at: '2008-10-30 15:14:25'
&lt;/pre&gt;


&lt;p&gt;Another example, to find informations about the blog post with slug &lt;code&gt;third-post&lt;/code&gt; and its associated comments:&lt;/p&gt;

&lt;pre&gt;
$ ./symfony doctrine:dql &amp;quot;Select p.title, p.author, c.author, c.content From BlogPost p, p.BlogComment c Where p.slug = 'third-post' Group by c.id&amp;quot;
found 3 results
-
  id: '23'
  title: 'Third post'
  author: 'Roger Hanin'
  BlogComment: [{ id: '15', author: John, content: 'Hey, you''re right there.' }, { id: '16', author: Paul, content: 'Nope, he''s not.' }]
&lt;/pre&gt;


&lt;h3&gt;Put the Query Logic in the Model&lt;/h3&gt;


&lt;p&gt;The Model part of any &lt;acronym title=&quot;Model View Controller&quot;&gt;MVC&lt;/acronym&gt; architecture must contains the business data and associated logic. In other words, these data and logic should never be handled anywhere else, to decouple your components at max. So we&amp;#8217;ll add some query methods in the &lt;code&gt;lib/model/doctrine/BlogPostTable.class.php&lt;/code&gt; file, which represents our &lt;code&gt;blog_post&lt;/code&gt; table and available operations on it:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; BlogPostTable extends Doctrine_Table
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getAll&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'p.title, p.slug, p.body, p.author, p.created_at, count(c.id) numcomments'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BlogPost p, p.BlogComment c'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;orderBy&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'p.created_at DESC'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;groupBy&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'p.id'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getOneBySlug&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$posts&lt;/span&gt; = Doctrine_Query::&lt;span style=&quot;color: #006600;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BlogPost p'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;leftJoin&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'p.BlogComment c'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'p.slug = ?'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;orderBy&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'c.created_at ASC'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;limit&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;
      &lt;span style=&quot;color: #006600;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
&amp;nbsp;
    &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$posts&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ? &lt;span style=&quot;color: #0000ff;&quot;&gt;$posts&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; : &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;h3&gt;A Weblog is About Web Interface, uh?&lt;/h3&gt;


&lt;p&gt;Okay, let&amp;#8217;s add pretty controllers and templates to give some life to our blog. First, generate a &lt;code&gt;post&lt;/code&gt; module in the &lt;code&gt;main&lt;/code&gt; app:&lt;/p&gt;


&lt;pre&gt;$ ./symfony generate:module main post&lt;/pre&gt;


&lt;p&gt;Then, edit the &lt;code&gt;apps/main/modules/post/actions/actions.class.php&lt;/code&gt; file:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; postActions extends sfActions
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeIndex&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;posts&lt;/span&gt; = Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;getTable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BlogPost'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getAll&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeShow&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt; = Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;getTable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BlogPost'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getOneBySlug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getParameter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'slug'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;forward404Unless&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'No post with slug='&lt;/span&gt; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;comments&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getBlogComment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;We should have display templates too. The first one will show the posts list, in &lt;code&gt;apps/main/modules/post/templates/indexSuccess.php&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$posts&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; include_partial&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post/post'&lt;/span&gt;, &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'numComments'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getNumcomments&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;hr/&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; endforeach; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Note that we must create the &lt;code&gt;_post&lt;/code&gt; partial template, in &lt;code&gt;apps/main/modules/post/templates/_post.php&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&amp;lt;h2&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; link_to&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getTitle&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'post/show?slug='&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getSlug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/h2&amp;gt;
&amp;lt;p&amp;gt;
  &amp;lt;small&amp;gt;Posted by &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getAuthor&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt; on &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getCreatedAt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/isset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;isset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$numComments&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    - &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$numComments&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt; comments
  &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;endif&lt;/span&gt;; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;/small&amp;gt;
&amp;lt;/p&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getBody&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;ESC_RAW&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;The other main template will display one post and its comments, in &lt;code&gt;apps/main/modules/post/templates/showSuccess.php&lt;/code&gt;:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; include_partial&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post/post'&lt;/span&gt;, &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
&amp;nbsp;
&amp;lt;h2&amp;gt;Comments&amp;lt;/h2&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comments&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;p&amp;gt;No comment yet.&amp;lt;/p&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comments&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;: &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;p&amp;gt;&amp;lt;small&amp;gt;By &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getAuthor&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt; on &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getCreatedAt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/small&amp;gt;&amp;lt;/p&amp;gt;
  &amp;lt;blockquote&amp;gt;&amp;lt;?php &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getContent&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; ?&amp;gt;&amp;lt;/blockquote&amp;gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; endforeach; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;endif&lt;/span&gt;; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;That&amp;#8217;s it. A rough but functional weblog if you lauch your browser to &lt;code&gt;yourhost/main_dev.php/post/index&lt;/code&gt;:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Dev/Doctrine/step2.png&quot; alt=&quot;step2.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;step2.png, oct. 2008&quot; /&gt;&lt;/p&gt;


&lt;p&gt;And if you click a post title:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Dev/Doctrine/step1.png&quot; alt=&quot;step1.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;step1.png, oct. 2008&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;Good News, the Forms Framework Works with Doctrine Too&lt;/h3&gt;


&lt;p&gt;Symfony 1.1 introduced the new &lt;a href=&quot;http://www.symfony-project.org/book/forms/1_1/en/&quot; hreflang=&quot;en&quot;&gt;forms framework&lt;/a&gt;, and good news, Doctrine can take part of it. So maybe you&amp;#8217;ve already noticed it, we have form classes generated already, in the &lt;code&gt;lib/form/doctrine&lt;/code&gt; folder of the project.&lt;/p&gt;


&lt;p&gt;So let&amp;#8217;s add a neat commenting system to our blog, by first editing the &lt;code&gt;lib/form/doctrine/BlogCommentForm.class.php&lt;/code&gt; file:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; BlogCommentForm extends BaseBlogCommentForm
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; configure&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;a href=&quot;http://www.php.net/unset&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;unset&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'created_at'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'updated_at'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;widgetSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'blog_post_id'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfWidgetFormInputHidden&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;validatorSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'author'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;  = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;validatorSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'email'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;   = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorEmail&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;validatorSchema&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'content'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; sfValidatorString&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'min_length'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;Now, use the form in the &lt;code&gt;executeShow()&lt;/code&gt; method of our controller:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// ...&lt;/span&gt;
  public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; executeShow&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt; = Doctrine::&lt;span style=&quot;color: #006600;&quot;&gt;getTable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'BlogPost'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getOneBySlug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getParameter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'slug'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;forward404Unless&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'No post with slug='&lt;/span&gt; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$slug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;comments&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getBlogComment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; BlogComment&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;setBlogPost&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;form&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; BlogCommentForm&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$comment&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    
    &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;isMethod&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;bindAndSave&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$request&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getParameter&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'blog_comment'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;
      &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;redirect&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post/show?slug='&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getSlug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;
    &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;


&lt;p&gt;And in the &lt;code&gt;showSuccess.php&lt;/code&gt; template, we&amp;#8217;ll append the form display:&lt;/p&gt;

&lt;pre class=&quot;php&quot;&gt;&amp;lt;h3&amp;gt;Add a comment&amp;lt;/h3&amp;gt;
&amp;nbsp;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;renderFormTag&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;url_for&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'post/show?slug='&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$post&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;getSlug&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
  &amp;lt;table&amp;gt;
    &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;&amp;lt;?php&lt;/span&gt; &lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;?&amp;gt;&lt;/span&gt;
    &amp;lt;tr&amp;gt;
      &amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;input type=&lt;span style=&quot;color: #ff0000;&quot;&gt;&amp;quot;submit&amp;quot;&lt;/span&gt;/&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;
&amp;lt;/form&amp;gt;&lt;/pre&gt;


&lt;p&gt;We&amp;#8217;ve now a pretty commeting system added to our blog, thanks to all the goodness provided by symfony and Doctrine:&lt;/p&gt;


&lt;p&gt;&lt;img src=&quot;http://prendreuncafe.com/blog/public/images/Dev/Doctrine/step3.png&quot; alt=&quot;step3.png&quot; style=&quot;display:block; margin:0 auto;&quot; title=&quot;step3.png, oct. 2008&quot; /&gt;&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;


&lt;p&gt;The time when everyone choosed Propel because it was more stable than Doctrine seems to be over. Doctrine is robust, and performs quite well on my box. Furthermore, it handles complex relationships and dynamic object hydratation natively and better than Propel. Doctrine is also very well integrated into symfony, certainly because Jonathan Wage - the Doctrine lead developer - now works for &lt;a href=&quot;http://sensiolabs.com/&quot; hreflang=&quot;en&quot;&gt;Sensio&lt;/a&gt;, creator and main sponsor of symfony.&lt;/p&gt;
&lt;div class=&quot;footnotes&quot;&gt;&lt;h4&gt;Notes&lt;/h4&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/10/31/#rev-pnote-999-1&quot; id=&quot;pnote-999-1&quot;&gt;1&lt;/a&gt;] Note that Windows users should replace calls to &lt;code&gt;./symfony&lt;/code&gt; by &lt;code&gt;php symfony&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;[&lt;a href=&quot;http://prendreuncafe.com/blog/post/2008/10/31/#rev-pnote-999-2&quot; id=&quot;pnote-999-2&quot;&gt;2&lt;/a&gt;] If you hate YAML, you can still write Doctrine table definition classes in raw PHP by hand&lt;/p&gt;&lt;/div&gt;&lt;hr/&gt;&lt;p style='margin:.5em 0;padding:.5em;border:1px solid #333;background:#eee;color:#222'&gt;&lt;small&gt;Ce billet intitulé &lt;a href='http://prendreuncafe.com/blog/post/2008/10/31/Playing-with-symfony-12-and-Doctrine'&gt;Let's Play with Symfony 1.2 and Doctrine&lt;/a&gt; a été rédigé par &lt;a href='http://prendreuncafe.com/cv'&gt;Nicolas Perriault&lt;/a&gt; et publié sur le blog &lt;a href='http://prendreuncafe.com/blog/'&gt;Prendre un Café&lt;/a&gt; sous licence &lt;a href='http://creativecommons.org/licenses/by-nc-sa/2.5/'&gt;Creative Commons BY-NC-SA&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;</description>
    
          <enclosure url="http://prendreuncafe.com/blog/public/upload/redist/doctrine_blog.tar.gz"
      length="7387115" type="application/x-gzip" />
    
    
          <comments>http://prendreuncafe.com/blog/post/2008/10/31/Playing-with-symfony-12-and-Doctrine#comment-form</comments>
      <wfw:comment>http://prendreuncafe.com/blog/post/2008/10/31/Playing-with-symfony-12-and-Doctrine#comment-form</wfw:comment>
      <wfw:commentRss>http://prendreuncafe.com/blog/feed/atom/comments/999</wfw:commentRss>
      </item>
    
  <item>
    <title>Utiliser Doctrine au lieu de Propel dans Symfony sous Ubuntu</title>
    <link>http://prendreuncafe.com/blog/post/2007/01/07/Utiliser-Doctrine-au-lieu-de-Propel-dans-Symfony-sous-Ubuntu</link>
    <guid isPermaLink="false">urn:md5:8de6053271d14bbb95afe9a12814ed64</guid>
    <pubDate>Sun, 07 Jan 2007 18:45:00 +0100</pubDate>
    <dc:creator>NiKo</dc:creator>
        <category>Dev</category>
        <category>doctrine</category><category>orm</category><category>php</category><category>plugins</category><category>symfony</category><category>tutoriel</category>    
    <description>    &lt;p&gt;&lt;a href=&quot;http://www.phpdoctrine.com/&quot; hreflang=&quot;en&quot;&gt;Doctrine&lt;/a&gt; est une couche &lt;acronym title=&quot;Object Relationnal Model&quot;&gt;ORM&lt;/acronym&gt; rapide et performante, basée sur le &lt;a href=&quot;http://en.wikipedia.org/wiki/Active_record&quot; hreflang=&quot;en&quot;&gt;pattern ActiveRecord&lt;/a&gt; bien connu des adeptes de &lt;a href=&quot;http://fr.wikipedia.org/wiki/Ruby_on_Rails&quot; hreflang=&quot;fr&quot;&gt;Ruby on Rails&lt;/a&gt;, pouvant être utilisée en lieu et place de &lt;a href=&quot;http://propel.phpdb.org/trac/&quot; hreflang=&quot;en&quot;&gt;Propel&lt;/a&gt;, l'ORM natif embarqué avec &lt;a href=&quot;http://www.symfony-project.com&quot; hreflang=&quot;en&quot;&gt;Symfony&lt;/a&gt; par défaut.&lt;/p&gt;


&lt;h3&gt;Installation&lt;/h3&gt;


&lt;p&gt;La mise en place de Doctrine se présente sous la forme d'un plugin, &lt;a href=&quot;http://www.symfony-project.com/trac/wiki/sfDoctrine&quot; hreflang=&quot;en&quot;&gt;sfDoctrine&lt;/a&gt;, qui s'installe via un checkout Subversion dans le répertoire &lt;code&gt;plugins&lt;/code&gt; de votre projet Symfony, comme suit :&lt;/p&gt;


&lt;pre&gt;$ cd /path/to/project/plugins
$ sudo apt-get install subversion
$ svn co http://svn.symfony-project.com/plugins/sfDoctrinePlugin sfDoctrinePlugin&lt;/pre&gt;


&lt;p&gt;Note: Si votre projet est déjà versionné dans un dépôt Subversion, vous pouvez faire un &lt;a href=&quot;http://svnbook.red-bean.com/en/1.0/ch07s03.html&quot; hreflang=&quot;en&quot;&gt;svn:externals&lt;/a&gt; vers le plugin :&lt;/p&gt;


&lt;pre&gt;$ propset svn:externals &amp;quot;symfony http://svn.symfony-project.com/plugins/sfDoctrinePlugin&amp;quot; /path/to/project/plugins&lt;/pre&gt;


&lt;p&gt;L'avantage est que desormais vos &lt;code&gt;svn up&lt;/code&gt; mettront à jour les fichiers du plugin d'un même coup.&lt;/p&gt;


&lt;p&gt;Ceci fait, il faut installer &lt;a href=&quot;http://fr.php.net/pdo&quot; hreflang=&quot;fr&quot;&gt;PDO&lt;/a&gt; et son driver MySQL via &lt;a href=&quot;http://pecl.php.net/&quot; hreflang=&quot;en&quot;&gt;PECL&lt;/a&gt; sur votre système si ce n'est pas déjà le cas :&lt;/p&gt;


&lt;pre&gt;$ sudo apt-get install build-essential php5-dev php-pear libmysqlclient12-dev
$ sudo pecl install PDO PDO_MySQL&lt;/pre&gt;


&lt;p&gt;C'est un peu long, puisque compilé à la volée. Il ne faut pas oublier d'activer notre nouvelle extension et son driver dans nos fichiers différents &lt;code&gt;php.ini&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;$ sudo vi /etc/php5/apache2/php.ini /etc/php5/cli/php.ini&lt;/pre&gt;


&lt;p&gt;Et ajoutez en toute fin de fichiers les deux lignes suivantes :&lt;/p&gt;


&lt;pre&gt;extension=pdo.so
extension=pdo_mysql.so&lt;/pre&gt;


&lt;h3&gt;Configuration&lt;/h3&gt;


&lt;p&gt;Maintenant, définissons nos paramètres de connexion pour le projet &lt;code&gt;monprojet&lt;/code&gt; dans le fichier &lt;code&gt;./config/databases.yml&lt;/code&gt; du projet :&lt;/p&gt;


&lt;pre&gt;all:
  monprojet:
    class: sfDoctrineDatabase
    param:
      dsn: mysql://user:pass@localhost/mydb&lt;/pre&gt;


&lt;p&gt;Ensuite, on va tester une structure de données assez simpliste (au pif et pour faire original, un blog), pour vérifier que ça marche. On édite le fichier &lt;code&gt;./config/doctrine/monprojet.yml&lt;/code&gt; :&lt;/p&gt;


&lt;pre&gt;User:
  tableName:     users
  columns:
    name:        string(20)
    created_at:  timestamp
Article:
  tableName:     articles
  columns:
    title:       string(255)
    exerpt:      text
    description: text
    created_at:  timestamp
    user_id:
      foreignClass: User
      foreignName:  author
      localName:    article_author
      onDelete:     cascade
Comment:
  tableName:     comments
  columns:
    content:     text
    created_at:  timestamp
    user_id:
      foreignClass: User
      foreignName:  commenter
      localName:    comment_user
      onDelete:     cascade
    article_id :
      foreignClass: Article
      localName:    comment_article
      onDelete:     cascade&lt;/pre&gt;


&lt;p&gt;On peut maintenant générer les classes du modèle objet précedemment défini :&lt;/p&gt;


&lt;pre&gt;$ symfony doctrine-build-model&lt;/pre&gt;


&lt;p&gt;Ce qui nous donne :&lt;/p&gt;


&lt;pre&gt;&amp;gt;&amp;gt; loading   Class descriptions from &amp;quot;/home/...m/config/doctrine/monprojet.yml&amp;quot;
&amp;gt;&amp;gt; writing   BaseUser.class.php
&amp;gt;&amp;gt; writing   BaseArticle.class.php
&amp;gt;&amp;gt; writing   BaseComment.class.php&lt;/pre&gt;


&lt;p&gt;Ces fichiers ont été créés sous &lt;code&gt;./lib/model/doctrine&lt;/code&gt; automatiquement. Vous pourrez modifier les classes objets pour les adapter à vos besoin, mais attention, les classes de base situées dans le sous-répertoire &lt;code&gt;generated&lt;/code&gt; seront systématiquement écrasées à chaque regénération.&lt;/p&gt;


&lt;h3&gt;Utilisation&lt;/h3&gt;


&lt;p&gt;Les commandes de scaffolding propres à Symfony et Propel ont été adaptées partiellement à Doctrine ; vous trouverez ainsi quelques tâches utiles :&lt;/p&gt;


&lt;pre&gt;doctrine-export            &amp;gt; exports doctrine schemas to propel schema.xml
doctrine-generate-crud     &amp;gt; Creates Doctrine CRUD Module
doctrine-import            &amp;gt; converts propel schema.*ml into doctrine schema
doctrine-init-admin        &amp;gt; initialize a new doctrine admin module&lt;/pre&gt;


&lt;h3&gt;Pour aller plus loin&lt;/h3&gt;


&lt;p&gt;La syntaxe de requêtage et les autres aspects de Doctrine sont détaillés dans les ressources suivantes :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.symfony-project.com/trac/wiki/sfDoctrine&quot; hreflang=&quot;en&quot;&gt;Sur le wiki de Symfony&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://doctrine.pengus.net/Main_Page&quot; hreflang=&quot;en&quot;&gt;Sur le wiki de Doctrine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.phpdoctrine.com/documentation.php&quot; hreflang=&quot;en&quot;&gt;La documentation officielle de Doctrine&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;hr/&gt;&lt;p style='margin:.5em 0;padding:.5em;border:1px solid #333;background:#eee;color:#222'&gt;&lt;small&gt;Ce billet intitulé &lt;a href='http://prendreuncafe.com/blog/post/2007/01/07/Utiliser-Doctrine-au-lieu-de-Propel-dans-Symfony-sous-Ubuntu'&gt;Utiliser Doctrine au lieu de Propel dans Symfony sous Ubuntu&lt;/a&gt; a été rédigé par &lt;a href='http://prendreuncafe.com/cv'&gt;Nicolas Perriault&lt;/a&gt; et publié sur le blog &lt;a href='http://prendreuncafe.com/blog/'&gt;Prendre un Café&lt;/a&gt; sous licence &lt;a href='http://creativecommons.org/licenses/by-nc-sa/2.5/'&gt;Creative Commons BY-NC-SA&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;</description>
    
    
    
      </item>
    
</channel>
</rss>
