<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>PHP Hints</title>
	<atom:link href="http://phphints.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://phphints.wordpress.com</link>
	<description>Tips for working with PHP</description>
	<lastBuildDate>Tue, 24 Jan 2012 15:21:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='phphints.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>PHP Hints</title>
		<link>http://phphints.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://phphints.wordpress.com/osd.xml" title="PHP Hints" />
	<atom:link rel='hub' href='http://phphints.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Bisna: Integrating Zend Framework and Doctrine 2 ORM</title>
		<link>http://phphints.wordpress.com/2011/08/09/integrating-zend-framework-and-doctrine-2-orm/</link>
		<comments>http://phphints.wordpress.com/2011/08/09/integrating-zend-framework-and-doctrine-2-orm/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 13:29:14 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=2339</guid>
		<description><![CDATA[Guilherme Blanco&#8217;s Bisna package integrates Doctrine 2 and Zend Framework 1 using a custom Zend Framework application resource plug: Bisna\Application\Resource\Doctrine Since configuration settings are stored in application.ini, the developer can easily switch between development and production environments. Bisna\Application\Resource\Doctrine creates the Bisna\Application\Doctrine\Container, the Doctrine Container instance, which it stores in the Zend registry. This is the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2339&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Guilherme Blanco&#8217;s <a class="reference external" href="https://github.com/guilhermeblanco/ZendFramework1-Doctrine2">Bisna package</a> integrates <a href="http://www.doctrine-project.org/projects/orm">Doctrine 2</a> and <a href="http://framework.zend.com/">Zend Framework 1</a> using a custom Zend Framework application resource plug: <span class><span class="pre">Bisna\Application\Resource\Doctrine</span></p>
<p><span id="more-2339"></span></p>
<p>Since configuration settings are stored in <b>application.ini</b>, the developer can easily switch between development and production environments. <span class="rst-literal">Bisna\Application\Resource\Doctrine</span> creates the <span class="rst-literal">Bisna\Application\Doctrine\Container</span>, the Doctrine Container instance, which it stores in the Zend registry. This is the class you will retrieve and use in your action controllers.</p>
<p>I have written full documentation on how to configure and use Bisna <a href="http://www.kurttest.com/zfa/bisna.html">here</a>. </p>
<p><b>Note:</b> Doctrine 2 requires at least PHP version 5.3.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/2339/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/2339/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/2339/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2339&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2011/08/09/integrating-zend-framework-and-doctrine-2-orm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Bisna to work with DoctrineCommon 2.1.0</title>
		<link>http://phphints.wordpress.com/2011/07/10/getting-bisna-to-work-with-doctrinecommon-2-1-0/</link>
		<comments>http://phphints.wordpress.com/2011/07/10/getting-bisna-to-work-with-doctrinecommon-2-1-0/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 13:56:33 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[2.1.0]]></category>
		<category><![CDATA[Bisna]]></category>
		<category><![CDATA[DoctrineORM. doctrine command line]]></category>
		<category><![CDATA[Metadata]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=2232</guid>
		<description><![CDATA[UPATED 7/21/2011 Guilherme Blanco has updated Bisna. It now works with Doctrine 2.1.0. Just download it from github. It now incorporates the changes mentioned below as of 7/21/2011. The Bisna library integrates Zend Framework version 1.x and the Doctrine 2 ORM; however, it dids not work properly with version 2.1.0 of the DoctrineCommon package. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2232&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><b>UPATED 7/21/2011</b> Guilherme Blanco has updated Bisna. It now works with <strong>Doctrine 2.1.0</strong>. Just download it from <a href="https://github.com/guilhermeblanco/ZendFramework1-Doctrine2" title="ZendFramework1-Doctrine2.">github</a>. It now incorporates the changes mentioned below as of 7/21/2011.</p>
<p>The Bisna library integrates <strong>Zend Framework version 1.x</strong> and the <a style='font-weight:bold;' href="http://www.doctrine-project.org/projects/orm">Doctrine 2 ORM</a>; however, it dids not work properly with version <strong>2.1.0</strong> of the <strong>DoctrineCommon</strong> package. This article shows how to get it to work.<br />
(actually, this article is now obsolete because Bisna now works with Doctrine 2.1.0)<br />
<span id="more-2232"></span><br />
Bisna can be downloaded from <a href="https://github.com/guilhermeblanco/ZendFramework1-Doctrine2" title="ZendFramework1-Doctrine2.">github</a>. To check your version of <strong>DoctrineCommon</strong> issue this command from the command line<br />
<pre class="brush: bash;">
sudo pear list -c  pear.doctrine-project.org
</pre><br />
If the version of <strong>pear.doctrine-project.org/DoctrineCommon</strong> is <strong>2.1.0</strong> (or higher), then you will need to change the <strong>startORMMetadata</strong> method in <strong>library/Bisna/Application/Container/DoctrineContainer.php</strong>.</p>
<p>Add the four lines of code mentioned by Ben Eberlei at <a href="https://github.com/doctrine/doctrine2/blob/master/UPGRADE_TO_2_1">https://github.com/doctrine/doctrine2/blob/master/UPGRADE_TO_2_1</a>. Modify this section of <strong>startORMMetadata()</strong><br />
<pre class="brush: php;">
// snip... 
// only the relevent section of startORMMetadata is shown here
 if ($reflClass-&gt;getName() == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver' 
      || $reflClass-&gt;isSubclassOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver')) {

    $annotationReaderClass = $driver['annotationReaderClass'];
    $annotationReader = new annotationReaderClass($this-&gt;getCacheInstance($driver['annotationReaderCache']));
    $annotationReader-&gt;setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');

    foreach ($driver['annotationReaderNamespaces'] as $alias =&gt; $namespace) {

          $annotationReader-&gt;setAnnotationNamespaceAlias($namespace, $alias);
    }
</pre><br />
to look like this<br />
<pre class="brush: php;">
  if ($reflClass-&gt;getName() == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver' ||
      $reflClass-&gt;isSubclassOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver')) {
      
      // For 2.1 add this line
      \Doctrine\Common\Annotations\AnnotationRegistry::registerFile('Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'); 

      $annotationReaderClass = $driver['annotationReaderClass'];

     $annotationReader = new  annotationReaderClass($this-&gt;getCacheInstance($driver['annotationReaderCache']));

      $annotationReader-&gt;setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
                
     // For 2.1 add the following three lines:
     $annotationReader-&gt;setIgnoreNotImportedAnnotations(true); 
     $annotationReader-&gt;setEnableParsePhpImports(false);        
     $annotationReader = new \Doctrine\Common\Annotations\CachedReader( 
               new \Doctrine\Common\Annotations\IndexedReader($annotationReader), 
               new \Doctrine\Common\Cache\ArrayCache());

      foreach ($driver['annotationReaderNamespaces'] as $alias =&gt; $namespace) {

             $annotationReader-&gt;setAnnotationNamespaceAlias($namespace, $alias);
     }
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/2232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/2232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/2232/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2232&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2011/07/10/getting-bisna-to-work-with-doctrinecommon-2-1-0/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Pear on XAMPP</title>
		<link>http://phphints.wordpress.com/2011/06/29/pear-on-xampp/</link>
		<comments>http://phphints.wordpress.com/2011/06/29/pear-on-xampp/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 18:24:28 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[XAMPP]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[pear packages]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=2202</guid>
		<description><![CDATA[These are the steps I following to get the pear command line utility pear.bat working under xampp for windows. 1. I downloaded the 7z&#8211;zipped version of xampp for windows and unzipped it to c:\xampp. 2. I installed the cygwin linux command line utilties for windows. 3. I ran the cygwin “as Administrator” (right click the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2202&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>These are the steps I following to get the pear command line utility <strong>pear.bat</strong> working under <a style="font-weight:bold;" href="http://www.apachefriends.org/en/xampp-windows.html">xampp for windows</strong></a>.<br />
<span id="more-2202"></span></p>
<p>1. I downloaded the 7z&#8211;zipped version of <a href="http://www.apachefriends.org/en/xampp-windows.html">xampp for windows</a> and unzipped it to c:\xampp.</p>
<p>2. I installed the <a href="http://www.cygwin.com" title="cygwin">cygwin</a> linux command line utilties for windows.</p>
<p>3. I ran the cygwin “as Administrator” (right click the Cygwin desktop icon and select “run as administrator”).</p>
<p>4. I changed the permissions of the <strong>c:\xampp</strong> directory to 777</p>
<p><pre class="brush: bash;">
# cd /cygdrive/c
# chmod -R 777 xampp

</pre></p>
<p>5. Set the PEAR configuration settings for <strong>data_dir</strong>, <strong>test_dir</strong> and <strong>doc_dir</strong>. For example,</p>
<p><pre class="brush: bash;">
# cd /cygdrive/c/xampp/php
# mkdir pear/data
# ./pear.bat config-set data_dir c:\\xampp\\php\\pear\\data
</pre></p>
<p>Do this for<strong> data_dir</strong>, <strong>test_dir</strong>, <strong>doc_dir</strong>, and <strong>cfg_dir</strong> as necessary. You will need to create the respective directories first (as shown above for <strong>data_dir</strong>). Note the use of double slashes! Also note: You may need to do the <strong>chmod -R 777</strong> again after the <strong>config-sets</strong>, to make the subdirectories read/write-able.</p>
<p>To see the current PEAR configuration do</p>
<p><pre class="brush: bash;">
# cd /cygdrive/c/xampp/php
# ./pear.bat config-show
</pre></p>
<p>after running Cygwin as Administrator.</p>
<p>6. Now install the packages you want. For example, this is how you would install<a href="http://www.doctrine-project.org/projects/orm" title="Doctrine 2 ORM"> Doctrine 2 ORM</a>. Again, I am doing this from the <strong>Cygwin shell</strong>.</p>
<p><pre class="brush: bash;">
# cd /cygdrive/c/xampp/php
# ./pear.bat channel-discover pear.doctrine-project.org
# ./pear.bat install pear.doctrine-project.org/DoctrineORM
</pre></p>
<p>If you want to update current packages:</p>
<p><pre class="brush: bash;">
# cd /cygdrive/c/xampp/php
# ./pear.bat update-channels
# ./pear.bat upgrade-all
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/2202/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/2202/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/2202/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2202&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2011/06/29/pear-on-xampp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Configuring XAMPP for virtual hosts</title>
		<link>http://phphints.wordpress.com/2011/05/09/configuring-xampp-for-virtual-hosts/</link>
		<comments>http://phphints.wordpress.com/2011/05/09/configuring-xampp-for-virtual-hosts/#comments</comments>
		<pubDate>Mon, 09 May 2011 23:57:27 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=2173</guid>
		<description><![CDATA[How to Setup Virtual Hosts on XAMPP explains how. Be sure to also add the section for localhost, as explained in the article; otherwise you won&#8217;t be able to access htt://localhost, which is the XAMPP start page.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2173&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://return-true.com/2010/06/how-to-set-up-virtual-hosts-in-xampp/">How to Setup Virtual Hosts on XAMPP</a> explains how.</p>
<p>Be sure to also add the section for <strong>localhost</strong>, as explained in the article; otherwise you won&#8217;t be able to access htt://localhost, which is the XAMPP start page.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/2173/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/2173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/2173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=2173&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2011/05/09/configuring-xampp-for-virtual-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Doctrine 2 ORM Cookbook example</title>
		<link>http://phphints.wordpress.com/2010/11/11/doctrine-2-orm-cookbook-example/</link>
		<comments>http://phphints.wordpress.com/2010/11/11/doctrine-2-orm-cookbook-example/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 19:39:28 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[Doctrine 2]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1980</guid>
		<description><![CDATA[The first portion of the Doctrine 2 ORM Cookbook example is available on sourceforge. See the included README.txt. Steps to setup the database and config both cli-config.php and cookbook.php. This setup assumes you have used pear to install Doctrine 2. To do so: UPDATED December 27th, 2010: Doctrine 2 is now no longer in beta [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1980&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The first portion of the Doctrine 2 ORM Cookbook example is available on <a href="https://sourceforge.net/projects/doctrine2cookbk/files">sourceforge</a>. See the included README.txt.</p>
<p><span id="more-1980"></span></p>
<p>Steps to setup the database and config both cli-config.php and cookbook.php. This setup assumes you have used pear to install Doctrine 2. To do so:</p>
<p><strong>UPDATED December 27th, 2010:</strong> Doctrine 2 is now no longer in beta</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
$sudo pear channel-discover pear.doctrine-project.org
$sudo pear install -o pear.doctrine-project.org/DoctrineORM
$sudo pear list -c pear.doctrine-project.org
</pre>
<p>This should also install the prerequisite packages: DoctrineCommon and DoctrineDBAL.<br />
Note:<strong> pear config-set preferred_state beta</strong> is no longer necessary because Doctrine 2 is no longer in beta!</p>
<p>1. Generate the schema from the command line using the doctrine command line tool. For example, on Linux</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   $ doctrine orm:schema-tool:create --dump-sql &gt; generated.sql
</pre>
<p>2. Edit generated.sql and add the following lines to the top. Use the database name of your choice.</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
    drop database if exists bugs_db_cb;
    create database bugs_db_cb;
    use bugs_db_cb;
</pre>
<p>3. Edit cli-config.php and cookbook.php. Change the $connectionOptions array parameters, specifying the name of the database, the database&#8217;s user, and its password. Remember to create a user of the database.</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   $connectionOptions = array(
        'driver' =&gt; 'pdo_mysql',
        'dbname' =&gt; 'bugs_db_cb', // your database name goes here
        'user' =&gt; 'bugs_db_cb',     // the db user goes here
        'password' =&gt; 'YOUR-PW-HERE',    // the password goes here
        'host' =&gt; 'localhost'
        );
</pre>
<p>4. Make sure that the <strong>Proxies</strong> subdirectory, the directory specified in the call to <strong>setProxyDir</strong> is writable by your webserver. This is particularly true when running in &#8220;development&#8221; mode.</p>
</p>
<p><pre class="brush: php;">
$config-&gt;setProxyDir(__DIR__ . '/Proxies');
$config-&gt;setProxyNamespace('Proxies');
</pre></p>
<p>4. Now, create the database. For example, from the command line</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   $ mysql -u root -p &gt; ./generated.sql
</pre>
<p>5. Confirm that the annotation mappings and the database schema are valid.</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   $ doctrine orm:validate-schema
</pre>
<p>6. This example uses the annoation driver. If you will to generate the xml mappings, do</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   $ doctrine orm:convert-mapping xml ./somesubdir
  </pre>
<p>6. Finally, run the code</p>
<pre style="font-family:'courier new', mono;font-size:1.2em;font-weight:bold;">
   http:://localhost/cookbook
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1980/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1980/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1980/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1980&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/11/11/doctrine-2-orm-cookbook-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>cli-config.php for Doctrine 2 ORM</title>
		<link>http://phphints.wordpress.com/2010/10/28/cli-config-php-for-doctrine-2-command-line-tool/</link>
		<comments>http://phphints.wordpress.com/2010/10/28/cli-config-php-for-doctrine-2-command-line-tool/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 05:04:51 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Doctrine ORM]]></category>
		<category><![CDATA[cli-config.php]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Doctrine 2]]></category>
		<category><![CDATA[Installation]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1945</guid>
		<description><![CDATA[The cli-config.php configuration file for the Doctrine cli<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1945&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This article shows how to set up <strong>cli-config.php</strong> for use with the Doctrine 2 command line utility, doctrine. It assumes you installed Doctrine 2 using <strong>pear</strong>.<br />
<span id="more-1945"></span><br />
<pre class="brush: bash;">
$ sudo pear channel-discover pear.doctrine-project.org
</pre><br />
Note: The channel-discover command above only has to be done once.<br />
<pre class="brush: bash;">
$ sudo pear install -o pear.doctrine-project.org/DoctrineCommon
</pre><br />
<!--more-->Three Doctrine 2 packages from the pear channel pear.doctrine-project.org will now be installed:</p>
<p><pre class="brush: bash;">
# pear list -c pear.doctrine-project.org
</pre><br />
On Ubuntu, all these packages will be located in <strong>/usr/share/php/Doctrine</strong>. There should be four subdirectories under <strong>Doctrine</strong>.<br />
<pre class="brush: bash;">
$ ls -1 /usr/share/php/Doctrine
Common
DBAL
ORM
Symfony
</pre><br />
and the doctrine command line utility, will be installed into <strong>/usr/bin</strong>. With this setup, you need to create a <strong>cli-config.php</strong>, in order to get the doctrine command line utility to work.</p>
<p>Place <strong>cli-config.php</strong> in your projects directory, where your code is. Don&#8217;t place it in /usr/bin. For each project, you will need a separate <strong>cli-config.php</strong>. The only real difference, of course, between each project&#8217;s <strong>cli-config.php</strong> will be the $connectionOptions variable. You need to manually create Entities and Proxies subdirectories. Make sure that the Proxies subdirectory is writeable by your webserver. </p>
<p>You will need to manually create both the Entities and Proxies subdirectories, under your project folder. Note: You may need to change the namespace for your proxies. For example, if your proxies&#8217; namespace is <strong>MyProject\Proxies</strong>, then use<br />
<pre class="brush: php;">
 $config-&gt;setNamespaceProxies('MyProject\Proxies')
</pre></p>
<p>in your project&#8217;s <strong>cli-config.php</strong>. Your Doctrine 2 classes in the Entities subdirectory need to be declared in the same namespace.<br />
You may also need to change the mapping drive. For example, if you are using xml files to provide your mappings, then you would need to do something like<br />
<pre class="brush: php;">
$driverImpl = new Doctrine\ORM\Mapping\Driver\XmlDriver(__DIR__.&quot;/config/mappings&quot;);
$config-&gt;setMetadataDriverImpl($driverImpl);
</pre></p>
<p>Here is cli-config.php that uses the annotations driver.</p>
<p><pre class="brush: php;">
require ‘Doctrine/ORM/Tools/Setup.php’;

// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();

// Define application environment
define('APPLICATION_ENV', &quot;development&quot;);

/*
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
*/

 $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
 $classLoader-&gt;register();
 $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
 $classLoader-&gt;register();

// configuration (2)
 $config = new \Doctrine\ORM\Configuration();

// Proxies (3)
 $config-&gt;setProxyDir(__DIR__ . '/Proxies');
 $config-&gt;setProxyNamespace('Proxies');

 $config-&gt;setAutoGenerateProxyClasses((APPLICATION_ENV == &quot;development&quot;));

// Driver (4)
 $driverImpl = $config-&gt;newDefaultAnnotationDriver(array(__DIR__.&quot;/Entities&quot;));
 $config-&gt;setMetadataDriverImpl($driverImpl);

// Caching Configuration (5)
 if (APPLICATION_ENV == &quot;development&quot;) {

     $cache = new \Doctrine\Common\Cache\ArrayCache();

 } else {

     $cache = new \Doctrine\Common\Cache\ApcCache();
 }

 $config-&gt;setMetadataCacheImpl($cache);
 $config-&gt;setQueryCacheImpl($cache);

 $connectionOptions = array(
    'driver' =&gt; 'pdo_mysql',
    'dbname' =&gt; 'bugs_db_cb',
    'user' =&gt; 'bugs_db_cb',
    'password' =&gt; 'kk0457',
    'host' =&gt; 'localhost');

 $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);

 $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
     'db' =&gt; new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em-&gt;getConnection()),
     'em' =&gt; new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
 ));
</pre><br />
IMPORTANT: Make sure your <b>include_path</b> for the command line is correctly set. To check this, run &#8220;php -i&#8221; from the command line and check the include_path and &#8220;Loaded Configuration File&#8221; setting, as PHP often uses a different php.ini when it is run from the command line!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1945/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1945/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1945/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1945&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/10/28/cli-config-php-for-doctrine-2-command-line-tool/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>_forward _redirect and redirector action helper</title>
		<link>http://phphints.wordpress.com/2010/08/18/_forward-_redirect-and-redirector-action-helper/</link>
		<comments>http://phphints.wordpress.com/2010/08/18/_forward-_redirect-and-redirector-action-helper/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 20:08:15 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[redirector]]></category>
		<category><![CDATA[_forward]]></category>
		<category><![CDATA[_redirect]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1758</guid>
		<description><![CDATA[What is the different between _forward, _redirect and the various redirector action helper methods<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1758&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What is the different between <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">_forward</span>, <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">_redirect</span> and the various <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">Redirector</span> action helper&#8217;s methods?</p>
<h4>1. <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">Zend_Controller_Action::_forward($action, $controller = null, $module = null, array $params = null)</h4>
<p>What does <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">_forward</span> do?  The dispatch loop order for a request (see this  <a href="http://www.zendframework.com/manual/en/zend.controller.basics.html">illustration</a> of the  request dispatch cycle):</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;background-color:#EEEEEE;font-weight:bold;">
preDispatch()
someAction()
postDispatch()
</pre>
<p><span id="more-1758"></span></p>
<p><span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">_forward</span> can be used to call other actions during any of these steps. If called in <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">preDispatch</span>, the currently requested action will be skipped in favor of the new one. Otherwise, if called in called in <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">someAction</span> or <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">postDispatch</span>, the current action is processed, and the dispatch loop is re-run, when the action requested in <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">_forward</span> is executed.</p>
<p>For example, here we forward to the indexAction in the IndexController located in the storefront module, and also set an email parameter in the request object.</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
class SomeController extends Zend_Controller_Action {
 public function someAction()
 {
  // snip...do some stuff and then call _forward()
   $this-&gt;_forward('index', 'index', 'storefront', array('email' =&gt; 'myemail@somedomain.com'));
 }
 // snip...
}
</pre>
<p>This is equivalent to doing:</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
class SomeController extends Zend_Controller_Action {
 public function someAction()
 {
  // snip...do some stuff and then call _forward()
   $request = $this-&gt;getRequest();
   $request-&gt;setModuleName('storefront')
               -&gt;setControllerName('index')
               -&gt;setActionName('index')
               -&gt;setParam('email', 'myemail@somedomain.com')
               -&gt;setDispatched(false);
  }
//snip...
}
</pre>
<p>Setting the dispatched flag to <strong>false</strong> in the request object ensures that the dispatch loop is re-run.</p>
<h4 style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">2. Zend_Controller_Action::_redirect($url, array $options = array())</h4>
<p>This method takes a URL and an optional set of options. By default, it performs an HTTP 302 redirect. (A 302 code means the requested resource resides temporarily under a different URI. Since the redirection may be altered on occasion, the client SHOULD continue to use the original Request-URI for future requests.) </p>
<h4 style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">3. Redirector action helper&#8217;s gotoSimple(), gotoRoute(), and gotoUrl()</h4>
<p style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">i. void  Zend_Action_Action_Helper_Redirectorr::gotoSimple(string $action, [string $controller = null], [string $module = null],<br /> [$params = array()])</p>
<p>Note: Calling <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">$this-&gt;_helper-&gt;redirect($action, $controller, $module, $params)</span> is a more succinct way of writing</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">
$redirector = $this-&gt;_helper-&gt;getHelper('Redirector');
$redirector-&gt;gotoSimple($action, $controller, $module, $param);
</pre>
<p>which is equivalent to</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">
$this-&gt;_helper-&gt;redirector-&gt;gotoSimple($action, $controller, $module, $param);
</pre>
<p>The parameters for <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">Zend_Controller_Action_Helper_Redirector::gotoSimple()</span> are identical to those of _forward. gotoSimple does an HTTP redirect, resulting in an new request object being created. _forward simply causes the dispatch loop for the current request to be re-run.</p>
<p>Examples</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
class Storefront_CustomerController extends Zend_Controller_Action {
	//snip ...
    public function sampleAction()
    {
	//snip...
   	$this-&gt;_helper-&gt;Redirector-&gt;gotoSimple('login');
    }
    public function loginAction()
    {
        //snip...
    }
}
</pre>
<p><span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">$this-&gt;_helper-&gt;Redirector-&gt;gotoSimple(&#8216;login&#8217;); </span> or equivlantly <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">$this-&gt;_helper-&gt;getHelper(&#8216;Redirector&#8217;)-&gt;gotoSimple(&#8216;login&#8217;);</span> will cause a redirect that results in a call to loginAction, in the same controller, the Storefront_CustomerController, in the same module, which here is Storefront. If the call were changed to</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
$this-&gt;_helper-&gt;Redirector-&gt;gotoSimple('index', 'Customer');
</pre>
<p>this would cause a redirect that results in a call to indexAction, in the Storefront_CustomerController, in the same storefront module. If the call were <span style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">$this-&gt;_helper-&gt;Redirector-&gt;gotoSimple(&#8216;index&#8217;, &#8216;index&#8217;, &#8216;default&#8217;);&nbsp;</span>, this would cause a redirect that results in a call to indexAction, in the Default_IndexController (or possibly IndexController, depending on whether the module prefix is required), in the default module.</p>
<p style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">ii. void  gotoRoute([ $urlOptions = array()], [string $name = null], [boolean $reset = false], [boolean $encode = true])
</p>
<p>gotoRoute uses a registered route to build the url. Below &#8216;blogArchive&#8217; route is registered in the Boostrap class. Then later<br />
an associate array of &#8216;blogArchive&#8217; route options is used to construct the url.</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

  // 'blogArchive' route registered in Bootstrap
   protected function _initRoutes()
   {
   // snip...
	$route = new Zend_Controller_Router_Route('blog/:year/:month/:day/:id',
	    	array('controller' =&gt; 'archive', 'module' =&gt; 'blog', 'action' =&gt; 'view'));

	$router-&gt;addRoute('blogArchive', $route);
    }
}

class BlogAdminController extends Zend_Controller_Action {
  protected $_redirector = null;

  public function init()
  {
      $this-&gt;_redirector = $this-&gt;_helper-&gt;getHelper('Redirector');
  }
  public function returnAction()
  {
     //snip ..
     // Redirect to blog archive. Builds the following URL:  /blog/2010/4/24/42
     $this-&gt;_redirector-&gt;gotoRoute(
            array('year' =&gt; 2010,
                  'month' =&gt; 4,
                  'day' =&gt; 24,
                  'id' =&gt; 42),
            'blogArchive'
        );
    }
}
</pre>
<p style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;font-weight:bold;">iii. void   gotoUrl  (string $url, [ $options = array()])</p>
<p>gotoUrl simply takes the URL (minus the base path).</p>
<pre style="font-family:'DejaVu Sans Mono', 'Courier New', monospace;color:blue;">
class AlternativeController extends Zend_Controller_Action {
    protected $_redirector = null;
    public function init()
    {
        $this-&gt;_redirector = $this-&gt;_helper-&gt;getHelper('Redirector');
    }
    public function myAction()
    {
        // snip...
        $this-&gt;_redirector-&gt;gotoUrl('/my-controller/my-action/param1/test/param2/test2');
        return; // never reached since default is to goto and exit
    }
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1758/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1758/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1758/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1758&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/08/18/_forward-_redirect-and-redirector-action-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Form Element Decorators</title>
		<link>http://phphints.wordpress.com/2010/07/27/zend-decorators/</link>
		<comments>http://phphints.wordpress.com/2010/07/27/zend-decorators/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 23:52:09 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[decorator design pattern]]></category>
		<category><![CDATA[decorators]]></category>
		<category><![CDATA[UML]]></category>
		<category><![CDATA[Zend_Form_Decorator]]></category>
		<category><![CDATA[Zend_Form_Decorator_Abstract]]></category>
		<category><![CDATA[Zend_Form_Element]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1628</guid>
		<description><![CDATA[This UML illustrates how Zend Framework employs decorators to tailor the appearance of individual Zend_Form_Elements. Don&#8217;t confuse Zend Decorators with the GOF decorator design pattern. Unlike decorator objects in the decorator design pattern, Zend Decorators do not act as transparent enclosures for Zend_Form_Elements. Decorators can&#8217;t be substituted for Zend_Form_Element because they don&#8217;t derive from a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1628&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This UML illustrates how Zend Framework employs <a href="http://framework.zend.com/manual/en/learning.form.decorators.html">decorators</a> to tailor the appearance of individual Zend_Form_Elements.</p>
<p><a href="http://phphints.files.wordpress.com/2010/07/zend_decorators8.png"><img class="aligncenter size-full wp-image-1708" title="zend_decorators" src="http://phphints.files.wordpress.com/2010/07/zend_decorators8.png" alt="" width="725" height="251" /></a></p>
<p style="text-align:center;">
<p><span id="more-1628"></span></p>
<p>Don&#8217;t confuse Zend Decorators with the <a href="http://c2.com/cgi/wiki?GangOfFour">GOF</a> <a href="http://en.wikipedia.org/wiki/Decorator_pattern">decorator design pattern</a>.  Unlike decorator objects in the decorator design pattern, Zend Decorators do not act as transparent enclosures for Zend_Form_Elements.  Decorators can&#8217;t be substituted for Zend_Form_Element because they don&#8217;t derive from a common base class or interface. Instead they serve as the rendering <a href="http://en.wikipedia.org/wiki/Strategy_pattern">strategy</a> for their associated element.</p>
<p>The Zend_Decorator_Interface does contains three methods shared by Zend_Form_Element. The most important is  render(). All Zend_Form_Element decorators derive from Zend_Decorator_Abstract, which derives from Zend_Decorator_Interface, and they must implement the render method.</p>
<p>Zend_Form_Decorator_Abstract does contain a reference to the Zend_Form_Element.  Zend_Form_Element, in turn, contains an array of Zend_Form_Decorator_Abstract–derived decorators. The render method of Zend_Form_Element iterates over its array of decorators to incrementally build the html for the form element. The decorators comprise the rendering strategy for the element. When an individual decorator&#8217;s render method is invoked, the decorator will call back to the Zend_Form_Element&#8217;s methods as needed.</p>
<p>Here is the relevant code excerpt from Zend_Form_Element::render($context)</p>
<p><pre class="brush: php;">
  //...snip
  $content = '';
   foreach ($this-&gt;getDecorators() as $decorator) {
            $decorator-&gt;setElement($this);
            $content = $decorator-&gt;render($content);
   }
   return $content;
</pre></p>
<p>There are five default form element decorators, which are called in the following order:</p>
<ol>
<li> Zend_Form_Decorator_ViewHelper</li>
<li> Zend_Form_Decorator_Errors</li>
<li> Zend_Form_Decorator_Description (if setDescription() was called)</li>
<li> Zend_Form_Decorator_HtmlTag</li>
<li> Zend_Form_Decorator_Label</li>
</ol>
<p>The output of the ViewHelper decorator becomes the input for the Errors decorator. The output of the Errors decorator becomes the input for the Description decorator and so on for the remaining decorators. The initial input into the ViewHelper decorator is the empty string.</p>
<p><pre class="brush: php;">
require_once	&quot;Zend/Form/Decorator/Abstract.php&quot;;
class My_Decorator_SimpleInput extends Zend_Form_Decorator_Abstract {

    protected $_format = '&lt;label for=&quot;%s&quot;&gt;%s&lt;/label&gt;&lt;input id=&quot;%s&quot; name=&quot;%s&quot; type=&quot;text&quot; value=&quot;%s&quot;/&gt;';

    public function render($content)
    {
        $element = $this-&gt;getElement();
        $name    = htmlentities($element-&gt;getFullyQualifiedName());
        $label   = htmlentities($element-&gt;getLabel());
        $id      = htmlentities($element-&gt;getId());
        $value   = htmlentities($element-&gt;getValue());

        $markup  = sprintf($this-&gt;_format, $name, $label, $id, $name, $value);
        return $markup;
    }
}

$decorator = new My_Decorator_SimpleInput();
$element   = new Zend_Form_Element('foo', array( 'label' =&gt; 'Foo', 'belongsTo' =&gt; 'bar', 'value' =&gt; 'test', 'decorators' =&gt; array($decorator)));
</pre></p>
<p>The form itself also has a set of default decorators that are automatically called when the form is rendered:</p>
<ol>
<li>Zend_Form_Decorator_FormElements</li>
<li>Zend_Form_Decorator_HtmlTag</li>
<li>Zend_Form_Decorator_Form</li>
</ol>
<p>Likewise, display groups and subforms have a set of default decorators that comprise its default rendering strategy:</p>
<ol>
<li>Zend_Form_Decorator_FormElements</li>
<li>Zend_Form_Decorator_HtmlTag</li>
<li>Zend_Form_Decorator_Fieldset</li>
<li>Zend_Form_Decorator_DtDdWrapper</li>
</ol>
<h4>custom decorators</h4>
<p>If the My_Decorator_SimpleInput class is cut and pasted into a separate file called SimpleInput.php (note: the file name must match the class name), then the setprefixPath() method of Zend_Form_Element will ensure that My_Decorator_SimpleInput is automatically loaded. </p>
<p><pre class="brush: php;">
$element1  = new Zend_Form_Element('foo', array('label' =&gt; 'Foo', 'belongsTo'  =&gt; 'bar',
          'value' =&gt; 'test',
          'prefixPath' =&gt; array('decorator' =&gt; array('My_Decorator' =&gt; '/home/kurt/public_html/test')),
           'decorators' =&gt; array('SimpleInput')) );

echo $element1;
</pre></p>
<p>To read further about Zend_Form_Element decorators see the tutorial at <a href="http://framework.zend.com/manual/en/learning.form.decorators.simplest.html">Decorator Basics</a> on the Zend Framework website.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1628/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1628/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1628/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1628&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/07/27/zend-decorators/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>

		<media:content url="http://phphints.files.wordpress.com/2010/07/zend_decorators8.png" medium="image">
			<media:title type="html">zend_decorators</media:title>
		</media:content>
	</item>
		<item>
		<title>local variables don&#8217;t display in Netbeans with php 5.3.2 and xdebug 2.0.5</title>
		<link>http://phphints.wordpress.com/2010/06/28/local-variables-dont-display-in-netbeans-with-php-5-3-2-and-xdebug-2-0-5/</link>
		<comments>http://phphints.wordpress.com/2010/06/28/local-variables-dont-display-in-netbeans-with-php-5-3-2-and-xdebug-2-0-5/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 02:43:14 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[PHP IDEs]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[local variables]]></category>
		<category><![CDATA[Lucid]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1585</guid>
		<description><![CDATA[After upgrading Ubuntu from Karmic to Lucid, local variables no longer display in Netbeans while debugging. The problem is due to an incompatibility between xdebug 2.0.5 and php5.3.2, as this article shows. UPDATE July 2, 2010 The article shows how to build Xdebug 2.1.0rc1 from source. However, since Xdebug 2.1 is now an offical release, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1585&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After upgrading Ubuntu from Karmic to Lucid, local variables no longer display in Netbeans while debugging.  The problem is due to an incompatibility between xdebug 2.0.5 and php5.3.2, as this <a href="http://icephoenix.us/php/xdebug-doesnt-show-local-variables-in-komodo-netbeans-or-eclipse-pdt/">article</a> shows.<br />
<span id="more-1585"></span><br />
UPDATE July 2, 2010<br />
The  <a href="http://icephoenix.us/php/xdebug-doesnt-show-local-variables-in-komodo-netbeans-or-eclipse-pdt/">article</a> shows how to build <strong>Xdebug 2.1.0rc1</strong> from source. <strong>However, since Xdebug 2.1 is now an offical release, download version 2.1.0 rather than 2.1.0rc1.</strong> This fixes the problem of local variable not appearing. To compile the source code, you will need the <strong>php5-dev</strong> package installed, and I believe also <strong>php-pear</strong>.<br />
<pre class="brush: bash;">
sudo aptitude install php5-dev php-pear
</pre><br />
 php5-dev contains <strong>phpize5</strong>.  After downloading the source for Xdebug 2.1.0 from <a href="http://www.xdebug.com/download.php">http://www.xdebug.com/download.php</a>, the steps for building <strong>Xdebug 2.1.0</strong> on Ubuntu are:<br />
<pre class="brush: plain;">
tar -xvzf xdebug-2.1.0.tgz
cd xdebug-2.1.0
phpize5
./configure
make
sudo cp modules/xdebug.so /usr/lib/php5/20090626+lfs/
</pre><br />
I created the following /etc/php5/conf.d/xdebug.ini:<br />
<pre class="brush: plain;">
zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
</pre><br />
Then restart apache2<br />
<pre class="brush: plain;">
sudo /etc/init.d/apache2 restart
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1585/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1585&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/06/28/local-variables-dont-display-in-netbeans-with-php-5-3-2-and-xdebug-2-0-5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend Framework findDependentRowset() and findParentRow() demo</title>
		<link>http://phphints.wordpress.com/2010/06/25/zend-framework-finddependentrowset-and-findparentrow-demo/</link>
		<comments>http://phphints.wordpress.com/2010/06/25/zend-framework-finddependentrowset-and-findparentrow-demo/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 15:56:11 +0000</pubDate>
		<dc:creator>kkruecke</dc:creator>
				<category><![CDATA[PHP Code]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[findDependentRowset]]></category>
		<category><![CDATA[findParentrow]]></category>
		<category><![CDATA[Zend_Db_Table relationships]]></category>

		<guid isPermaLink="false">http://phphints.wordpress.com/?p=1488</guid>
		<description><![CDATA[The Zend_Db_Table Relationships discussion in the online help http://www.zendframework.com/manual/en/zend.db.table.relationships.html does not include a working database. This example provides a working database example.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1488&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a working example of the Zend_Db_Table_Row methods <strong>findDependRowset()</strong> and <strong>findParentrow()</strong>. Create the test database using this <strong>sample.sql</strong>:<br />
<span id="more-1488"></span><br />
<pre class="brush: sql;">
drop database if exists bugs;
create database if not exists bugs;

use bugs;

grant select, create, alter, drop, index, insert, update, delete on bugs.* to bugs@localhost identified by 'bugs'; 

CREATE TABLE IF NOT EXISTS accounts (
  account_id         INT UNSIGNED NOT NULL AUTO_INCREMENT,
  account_name      VARCHAR(100) NOT NULL,
  PRIMARY KEY       (account_id),
  UNIQUE            (account_name) 
) TYPE = InnoDB;

insert into accounts(account_name) values('kurt'), ('bill'), ('joe'), ('sam'), ('john'), ('dave');

CREATE TABLE IF NOT EXISTS products (
  product_id        INT UNSIGNED NOT NULL AUTO_INCREMENT,
  product_name      VARCHAR(100),
  PRIMARY KEY (product_id)
) TYPE = InnoDB;

insert into products(product_id, product_name) values('', 'PHP Storefont Application'), ('', 'C++ Game Application'), ('', 'C# Tax Return Application');

CREATE TABLE IF NOT EXISTS  bugs (
  bug_id            INT UNSIGNED NOT NULL AUTO_INCREMENT,
  bug_description   VARCHAR(100),
  bug_status        VARCHAR(20),
  reported_by       VARCHAR(100) REFERENCES accounts(account_id),
  assigned_to       VARCHAR(100) REFERENCES accounts(account_id),
  verified_by       VARCHAR(100) REFERENCES accounts(account_id),
  PRIMARY KEY	    (bug_id)
) TYPE=InnoDB;

insert into bugs(bug_id, bug_description, bug_status, reported_by, assigned_to, verified_by)
  values(1, 'Error 123 in PHP Storefront Application', 'NEW', 4, 1, 6),
   (2, 'Error 456 in C++ Game Application', 'NEW', 5, 2, 4),
   (3, 'Error 456 in C++ Game Application', 'NEW', 5, 1, 4),
   (4, 'Error 789 in C# Tax Return Application', 'NEW', 6, 3, 5),
   (5, 'Error 101112 C# Tax Return Application', 'NEW', 6, 3, 5),
   (6, 'Error 131415 PHP Storefront Application', 'NEW', 4, 3, 5),
   (7, 'Error 1151617 C# Tax Return Application', 'NEW', 4, 3, 4);

CREATE TABLE IF NOT EXISTS bugs_products (
  bug_id            INT UNSIGNED NOT NULL REFERENCES bugs,
  product_id        INT UNSIGNED NOT NULL REFERENCES products,
  PRIMARY KEY       (bug_id, product_id)
) TYPE=InnoDB;

insert into bugs_products(bug_id, product_id) values(1, 1), (2, 2), (3, 2), (4,3), (5,3),(6,3), (7,3);

</pre></p>
<p>This graphic shows the primary keys (PK) and illustrates the foreign key (FK) relationships between these tables.</p>
<p><img src="http://phphints.files.wordpress.com/2010/10/zenddb.jpg" />.</p>
<p>To test <strong>findDependentRowse()</strong> and <strong>findParentrow()</strong>, we start with this code, which contains our <strong>Zend_Db_Table_Abstract</strong> derived classes corresponding to our SQL tables. Make sure that the Zend Framework library is in your <strong>include_path</strong> in php.ini.</p>
<p><pre class="brush: php;">
&lt;?php
// assumes include_path points to zend framework library directory.
require_once &quot;Zend/Db.php&quot;;
require_once &quot;Zend/Db/Table/Abstract.php&quot;;

class Accounts extends Zend_Db_Table_Abstract {
    protected $_name            = 'accounts';
    protected $_dependentTables = array('Bugs');
}

class Products extends Zend_Db_Table_Abstract {
    protected $_name            = 'products';
    protected $_dependentTables = array('BugsProducts');
}

class Bugs extends Zend_Db_Table_Abstract {
    protected $_name            = 'bugs';
    protected $_dependentTables = array('BugsProducts');

    protected $_referenceMap    = array(
        'Reporter' =&gt; array(
            'columns'           =&gt; 'reported_by',
            'refTableClass'     =&gt; 'Accounts',
            'refColumns'        =&gt; 'account_id'
        ),
        'Engineer' =&gt; array(
            'columns'           =&gt; 'assigned_to',
            'refTableClass'     =&gt; 'Accounts',
            'refColumns'        =&gt; 'account_id'
        ),
        'Verifier' =&gt; array(
            'columns'           =&gt; array('verified_by'),
            'refTableClass'     =&gt; 'Accounts',
            'refColumns'        =&gt; array('account_id')
        )
    );
}
class BugsProducts extends Zend_Db_Table_Abstract {
    protected $_name = 'bugs_products';

    protected $_referenceMap    = array(
        'Bug' =&gt; array(
            'columns'           =&gt; array('bug_id'),
            'refTableClass'     =&gt; 'Bugs',
            'refColumns'        =&gt; array('bug_id')
        ),
        'Product' =&gt; array(
            'columns'           =&gt; array('product_id'),
            'refTableClass'     =&gt; 'Products',
            'refColumns'        =&gt; array('product_id')
        )
    );
}
</pre><br />
 The <strong>_referenceMap</strong> class variable defines an array of foreign key reference rules. Each reference rule identifies 1.) the parent (referenced) table in the relationship, and 2.) it also lists which columns in the dependent table reference which columns in the parent (referenced)  table.</p>
<p>A parent table is a table referenced by a foreign key. In our database, the Bugs SQL table, for example, has three foreign keys. All three foreign keys reference the Accounts table. This is why Bug&#8217;s _referenceMap has three associative subarrays.  The key of each subarray is used to identify each reference relationship. We choose descriptive names for each rule key.</p>
<p>In the code above, the rule keys in the Bugs table class are: &#8216;Reporter&#8217;, &#8216;Engineer&#8217;, and &#8216;Verifier&#8217;.</p>
<p>The <strong>&#8216;refTableClass&#8217;</strong> is obviously the referenced table and <strong>&#8216;refColumns&#8217;</strong> is the referenced column(s) that <strong>&#8216;columns&#8217;</strong> references.</p>
<p>We will use this class for displaying Zend_Db_Table_Rowset and Zend_Db_Table_Row objects as HTML tables.</p>
<p><pre class="brush: php;">
class HtmlTable { // displays Zend_Db_Table_Rowset and Zend_Db_Table_Row objects

  private $thead;
  private $info;

  public function __construct(Zend_Db_Table_Abstract $table)
  {
    $this-&gt;info = $table-&gt;info();

    $this-&gt;thead = &quot;&lt;thead&gt;\n&quot;;

    foreach($this-&gt;info['cols']  as $column) {

        $this-&gt;thead .= &quot;&lt;th&gt;$column&lt;/th&gt;&quot;;
    }

	$this-&gt;thead .= &quot;&lt;/thead&gt;\n&quot;;
  }

function displayRowset(Zend_Db_Table_Rowset $rowset)
{
    $table = &quot;&lt;table border=1&gt;&quot;;

    $table .= $this-&gt;thead;

    $table .= &quot;&lt;tbody&gt;\n&quot;;
       
    foreach($rowset as $row) {

        $table .= &quot;&lt;tr&gt;&quot;;
        
         foreach ($this-&gt;info['cols'] as $column) {

             $table .= &quot;&lt;td&gt;$row[$column]&lt;/td&gt;&quot;;
         }

         $table .= &quot;&lt;/tr&gt;\n&quot;;
    }
    
    echo $table . &quot;&lt;/tbody&gt;\n&lt;/table&gt;\n&quot;;
}

function displayRow(Zend_Db_Table_Row $row, $caption = null)
{
    $table = &quot;&lt;table border=1&gt;&quot;;

    if (!is_null($caption)) {

		$table .= &quot;&lt;caption&gt;$caption&lt;/caption&gt;&quot;;
    }

    $table .= $this-&gt;thead;

    $table .= &quot;&lt;tbody&gt;\n&lt;tr&gt;\n&quot;;
   
    foreach ($this-&gt;info['cols'] as $column) {

        $table .= &quot;&lt;td&gt;$row[$column]&lt;/td&gt;&quot;;
    }

    echo $table . &quot;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;\n&quot;;
 }
} // end class  
</pre></p>
<p>First, we use the factory method of Zend_Db to return a Zend_Db_Adapter instance, and set it as the default adapter. All our tables will thereafter use this default adpater.</p>
<p><pre class="brush: php;">
$db = Zend_Db::factory('Pdo_Mysql', array(
    'host'             =&gt; 'localhost',
    'username'         =&gt; 'bugs',
    'password'         =&gt; 'bugs',
    'dbname'           =&gt; 'bugs'
));

// set default adapter
Zend_Db_Table_Abstract::setDefaultAdapter($db);</pre></p>
<p>Next, we instantiate a Bugs object and display a Row set from it, using our HtmlTable class.</p>
<p><pre class="brush: php;">
$bugs = new Bugs();

$bugs_htmlTable = new HtmlTable($bugs);

// returning an instance of Zend_Db_Table_Rowset
$bugsRowset1 = $bugs-&gt;fetchAll($bugs-&gt;select()-&gt;where('bug_id &gt;= ?', 1)-&gt;order('bug_id'));

echo '&lt;pre class=&quot;code&quot;&gt;$bugs-&gt;select()-&gt;where(&quot;bug_id &gt;= ?&quot;, 1)-&gt;order(&quot;bug_id&quot;)));&lt;/pre&gt;'.&quot;\n&quot;;

$bugs_htmlTable-&gt;displayRowset($bugsRowset1);</pre></p>
<p>Next, we instantiate an Accounts object and find the row whose <strong>account_name</strong> is <strong>sam</strong>.</p>
<p><pre class="brush: php;">
$accounts = new Accounts();

$accounts_htmlTable = new HtmlTable($accounts);

$user_sam = $accounts-&gt;fetchRow($accounts-&gt;select()-&gt;where('account_name = ?', 'sam')); // searches primary key of &quot;sam&quot;.

echo &quot;&lt;p&gt;Find the bugs reported by the user whose &lt;strong&gt;account_name&lt;/strong&gt; is sam.&lt;/p &gt;\n&quot;;
echo &quot;&lt;p&gt;1. First, we get the corresponding row from the &lt;strong&gt;accounts&lt;/strong&gt; table where &lt;b&gt;account_name = sam&lt;/b&gt;&lt;/p&gt;\n&quot;;

echo '&lt;pre class=&quot;code&quot;&gt;$user_sam = $accounts-&gt;fetchRow($accounts-&gt;select()-&gt;where(&quot;account_name = ?&quot;, &quot;sam&quot;));&lt;/pre&gt;'.&quot;\n&quot;;

$accounts_htmlTable-&gt;displayRow($user_sam);
</pre></p>
<p>Next, we find all the bugs that <strong>sam</strong> has reported using findDependentRowset(&#8216;Bugs&#8217;, &#8216;Reporter&#8217;). This will find all the rows in the Bugs table where <strong>reported_by</strong> equals the unique <b>account_id</b> for <b>sam</b>.</p>
<p><pre class="brush: php;">
// this will be a Row set consisting of all bugs reported by user &quot;sam&quot;.
$bugsReportedBySam = $user_sam-&gt;findDependentRowset('Bugs', 'Reporter');

echo &quot;&lt;hr /&gt;\n&quot;;

$bugsRowset_htmltable-&gt;display($bugsReportedBySam);
</pre></p>
<p>We can also add an optional select statement as a third parameter. Here, we add <strong>ORDER BY reported_by ASC LIMIT 2</strong> to the SQL query internally generated by Zend Framework when findDependentRowset() executes.</p>
<p><pre class="brush: php;">
$select = $accounts-&gt;select()-&gt;order('reported_by ASC')-&gt;limit(2);

echo '&lt;pre class=&quot;code&quot;&gt;$accounts-&gt;find(&quot;sam&quot;)-&gt;current()-&gt;findDependentRowset(&quot;Bugs&quot;, &quot;Reporter&quot;, $accounts-&gt;select()-&gt;order(&quot;reported_by ASC&quot;)-&gt;limit(2));&lt;/pre&gt;'.&quot;\n&quot;;

$bugsReportedBySamLimitToTwo = $user_sam-&gt;findDependentRowset('Bugs', 'Reporter', $select);

$bugs_htmlTable-&gt;displayRowset($bugsReportedBySamLimitToTwo);
</pre></p>
<p>Finally, we find all bugs whose <strong>bug_status</strong> equals &#8220;NEW&#8221;, and we get the first row from this row set using <strong>current()</strong>. Then we call</p>
<p><strong>findParentRow(&#8216;Accounts&#8217;)</strong></p>
<p>on the row object returned by <strong>current()</strong>. This will retrieve the row object in the referenced or parent Accounts table.</p>
<p>There will be exactly one row in the parent table referenced by a dependent row, therefore <strong>findParentRow(&#8216;Accounts&#8217;)</strong> returns a Row object, not a Rowset object.</p>
<p>The first argument is a string that specifies the parent table by its class name (though it can specify the parent table by using an object of that table class).</p>
<p><pre class="brush: php;">
$bugsRowset2 = $bugs-&gt;fetchAll(array('bug_status = ?' =&gt; 'NEW'));

$bugRow = $bugsRowset2-&gt;current();

echo  '&lt;pre class=&quot;code&quot;&gt;$bugs-&gt;fetchAll(array(&quot;bug_status = ?&quot; =&gt; &quot;NEW&quot;)-&gt;current());&lt;/pre&gt;';

$bugs_htmlTable-&gt;displayRow($bugRow);

$reporter = $bugRow-&gt;findParentRow('Accounts');

echo '&lt;pre class=&quot;code&quot;&gt;$bugs-&gt;fetchAll(array(&quot;bug_status = ?&quot; =&gt; &quot;NEW&quot;)-&gt;current()-&gt;findParentRow(&quot;accounts&quot;);&lt;/pre&gt;'.&quot;\n&quot;;

$accounts_htmlTable-&gt;displayRow($reporter);
</pre>	</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/phphints.wordpress.com/1488/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/phphints.wordpress.com/1488/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/phphints.wordpress.com/1488/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=phphints.wordpress.com&amp;blog=4543399&amp;post=1488&amp;subd=phphints&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://phphints.wordpress.com/2010/06/25/zend-framework-finddependentrowset-and-findparentrow-demo/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fe95cefd071d101efc4836e29ce3d14d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kkruecke</media:title>
		</media:content>

		<media:content url="http://phphints.files.wordpress.com/2010/10/zenddb.jpg" medium="image" />
	</item>
	</channel>
</rss>
