<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sproif.com &#187; ant</title>
	<atom:link href="http://sproif.com/tag/ant/feed/" rel="self" type="application/rss+xml" />
	<link>http://sproif.com</link>
	<description>Everything you never wanted to read about... and less!</description>
	<lastBuildDate>Wed, 15 Jul 2009 12:10:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ants in my Zend Framework (with doctrine for good measure)</title>
		<link>http://sproif.com/2009/07/15/ants-in-my-zend-framework-with-doctrine-for-good-measure/</link>
		<comments>http://sproif.com/2009/07/15/ants-in-my-zend-framework-with-doctrine-for-good-measure/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 12:08:22 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Technical Jargon]]></category>
		<category><![CDATA[ant]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://sproif.com/?p=137</guid>
		<description><![CDATA[A few simple steps will free you from running your doctrine tasks from the command line.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m starting to use <a title="Zend Framework Home" href="http://zendframework.com/" target="_blank">Zend Framework 1.8.4</a> with <a title="Doctrine Object Relational Mapper Home" href="http://www.doctrine-project.org/">Doctrine Object Relational Mapper</a> (because after working on a java/<a title="Hibernate Homepage" href="https://www.hibernate.org/" target="_blank">hibernate</a> project, I can&#8217;t go back to writing SQL and building databases)  With Doctrine ORM, you can define a <a title="Example of a Doctrine data model in YAML" href="http://www.doctrine-project.org/documentation/manual/1_0/en/yaml-schema-files">data model in  YAML</a> or XML and it will build the database with foreign keys, etc, etc ,etc&#8230; learn more on that here.</p>
<p>On starting my project, I looked around to see what everyone else was doing.  Since 1.8.4 is relatively new, and there were some pretty neat changes, there aren&#8217;t many good tutorials out there.</p>
<p>That being said, and because of said java/hibernate project I&#8217;ve been working on, I&#8217;ve become quite familiar with <a title="Apache Ant Home" href="http://ant.apache.org/">Apache Ant</a>.  It&#8217;s basically an easy way to do some of the mundane work and sometimes heavy lifting in day to day programming.  That, and I use <a title="Eclipse Development Environment" href="http://www.eclipse.org/">Eclipse IDE</a>, so wasn&#8217;t too fond of always running to the command prompt to rebuild my models, create a zend module, etc.</p>
<p>So here&#8217;s what I&#8217;ve come up with.</p>
<p>I started with this tutorial: <a title="Tutorial on setting up a doctrine/zend project." href="http://www.danceric.net/2009/06/06/doctrine-orm-and-zend-framework/" target="_blank">Doctrine ORM and Zend Framework</a> It shows you how to create a Zend 1.8.4 project with doctrine.  The key aspect is the doctrine-cli.php script.</p>
<p>I should let you know, while I do use Eclipse for most of my projects, a while back I bought <a title="Zend Studio Homepage" href="http://www.zend.com/products/studio/" target="_blank">Zend Studio for Eclipse</a>. I think it&#8217;s much better for writing PHP than any plugin for eclipse (<a title="PDT PHP Eclipse Plugin" href="http://www.eclipse.org/pdt/">PDT</a>, <a title="PHP Eclipse Plugin" href="http://www.phpeclipse.com/">PHPEclipse</a>).  If you write a lot of PHP, ZS4E is very very worth the money.  While it does say it is &#8220;zend studio <strong>for</strong> eclipse&#8221;, it installs its own installation of eclipse.  If you find yourself in this boat, and want to use Ant in Zend Studio for Eclipse, check out <a title="Enabling Apache Ant in Zend Studio for Eclipse" href="http://damagestudios.net/blog/2009/01/12/ant-and-zend-studio" target="_blank">this tutorial</a>.  It&#8217;s rather screwy that you can&#8217;t install ant tools easily, but this definitely does the trick.</p>
<p>But I digress&#8230; let&#8217;s get started.</p>
<p>Here is the directory structure of my project, basically defined by the above tutorial:</p>
<pre class="brush: plain;">- root
-  htdocs [zend framework project root]
    - application
        - [all application folders]
        - doctrine
    - library
    - public
    - scripts
    - test
-  .project
-  build.xml
-  env.properties</pre>
<p>The body of env.properties looks like this:</p>
<pre class="brush: plain;">zf.project.basedir=htdocs
doctrine.scripts.path=${zf.project.basedir}/scripts</pre>
<p>And the body of the build.xml looks like this:</p>
<pre class="brush: xml;">&lt;project name=&quot;zf-doctrine-project&quot;&gt;
     &lt;property file=&quot;env.properties&quot; /&gt;
     &lt;target name=&quot;doctrine.cli&quot; description=&quot;Run a doctrine task on doctrine-cli.php - default reload&quot;&gt;
          &lt;input message=&quot;Enter a task:&quot;
               addproperty=&quot;doctrine.task&quot;
               defaultvalue=&quot;build-all-reload&quot; /&gt;
          &lt;fail unless=&quot;doctrine.task&quot; message=&quot;No task selected&quot; /&gt;
          &lt;exec dir=&quot;${doctrine.scripts.path}&quot;
               command=&quot;php doctrine-cli.php ${doctrine.task} y&quot;/&gt;
     &lt;/target&gt;
&lt;/project&gt;</pre>
<p>Although it&#8217;s painfully self-explanatory, for the sake of completeness, here&#8217;s what it does, line by line:</p>
<p>2.  Loads in the env.properties file<br />
3.  Defines the target, which is like a job/task in ant<br />
4. &#8211; 6.  Prompts the user to enter a task to pass to the cli script (just like you would pass in the command line)<br />
7.  Makes sure the user enters a value<br />
8. &#8211; 9. Executes the php script, passing in the entered task as a command line option, and forces yes to &#8220;are you sure?&#8221;</p>
<p>Now, the fun part.</p>
<p>In your project in Eclipse, open the ant window by going to Window &gt; Show View &gt; Other and select Ant under the Ant folder.  When you see the Ant View, either open your ant file in that window using it&#8217;s open dialog, or just drag your build.xml to that panel.  You&#8217;ll see the little white file with the ant on it and whatever you have as the name attribute of the &lt;project&gt; tag in your build xml.  Expand that so you can see the targets, and you should see this:</p>
<div id="attachment_138" class="wp-caption aligncenter" style="width: 285px"><img class="size-full wp-image-138 " title="Eclipse Ant View" src="http://sproif.com/wp-content/uploads/2009/07/eclipseantview.jpg" alt="Showing the doctrine task in the eclipse ant view" width="275" height="190" /><p class="wp-caption-text">Showing the doctrine task in the eclipse ant view</p></div>
<p>Now if you double click that target, you should see a prompt for the task you want to run.  The default value there will run your schema.yml and rebuild your db and models.</p>
<p>Crafty kids may notice that i have the &#8220;Hide internal targets button&#8221; turned on in that image&#8230; well, those targets are for another show&#8230;  (damn you crafty kids&#8230;)</p>

<span class="slashdigglicious">
<a href="http://slashdot.org/bookmark.pl?url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Slashdot It!"><img src="http://slashdot.org/favicon.ico" height="16" width="16" alt="[Slashdot]" /></a>
<a href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Digg This Story"><img src="http://digg.com/favicon.ico" width="16" height="16" alt="[Digg]" /></a>
<a href="http://reddit.com/submit?url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Reddit"><img src="http://reddit.com/favicon.ico" width="16" height="16" alt="[Reddit]" /></a>
<a href="http://del.icio.us/post?url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Save to del.icio.us" onclick="window.open('http://del.icio.us/post?v=4&amp;noui&amp;jump=close&amp;url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29', 'delicious', 'toolbar=no,width=700,height=400'); return false;"><img src="http://images.del.icio.us/static/img/delicious.small.gif" width="16" height="16" alt="[del.icio.us]" /></a>
<a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F" title="Share on Facebook"><img src="http://www.facebook.com/favicon.ico" width="16" height="16" alt="[Facebook]" /></a>
<a href="http://technorati.com/faves?add=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F" title="Add to my Technorati Favorites"><img src="http://technorati.com/favicon.ico" width="16" height="16" alt="[Technorati]" /></a>
<a href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Save to Google Bookmarks"><img src="http://www.google.com/favicon.ico" width="16" height="16" alt="[Google]" /></a>
<a href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fsproif.com%2F2009%2F07%2F15%2Fants-in-my-zend-framework-with-doctrine-for-good-measure%2F&amp;title=Ants+in+my+Zend+Framework+%28with+doctrine+for+good+measure%29" title="Stumble it!"><img src="http://www.stumbleupon.com/favicon.ico" width="16" height="16" alt="[StumbleUpon]" /></a>
</span>]]></content:encoded>
			<wfw:commentRss>http://sproif.com/2009/07/15/ants-in-my-zend-framework-with-doctrine-for-good-measure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
