<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://fashion.hosmoz.net/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/">
<channel>
  <title>Digital Fashion - zend framework</title>
  <link>http://fashion.hosmoz.net/</link>
  <description>Rien de grand ne se fit jamais sans enthousiasme.</description>
  <language>en</language>
  <pubDate>Wed, 06 Aug 2008 10:15:15 +0200</pubDate>
  <copyright>2003-2007 &amp;copy; Geoffrey Bachelet</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>Zend Framework 1.5.1 PEAR package is available</title>
    <link>http://fashion.hosmoz.net/post/2008/03/31/Zend-Framework-151-PEAR-package-is-available</link>
    <guid isPermaLink="false">urn:md5:4d8dcb3deedffc0ab3eb1d830c186f45</guid>
    <pubDate>Mon, 31 Mar 2008 17:08:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>package</category><category>pear</category><category>phpmafia</category><category>zend framework</category>    
    <description>    &lt;p&gt;A little late sorry, but ZF 1.5.1's package is now ready.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/03/31/Zend-Framework-151-PEAR-package-is-available#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/03/31/Zend-Framework-151-PEAR-package-is-available#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1093</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.5 PEAR package is available</title>
    <link>http://fashion.hosmoz.net/post/2008/03/22/Zend-Framework-15-PEAR-package-is-available</link>
    <guid isPermaLink="false">urn:md5:f6deb9b27f134853c91f21d4c952614f</guid>
    <pubDate>Sat, 22 Mar 2008 18:19:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>1.5</category><category>package</category><category>pear</category><category>phpmafia</category><category>zend framework</category>    
    <description>    &lt;p&gt;The long awaited 1.5 version of the &lt;a href=&quot;http://framework.zend.com/&quot;&gt;Zend Framework&lt;/a&gt; has landed for some days already, and here comes its pear package. Please note the api version changed to 1.5 in this package.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/03/22/Zend-Framework-15-PEAR-package-is-available#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/03/22/Zend-Framework-15-PEAR-package-is-available#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1090</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.0.4 PEAR package is available</title>
    <link>http://fashion.hosmoz.net/post/2008/02/27/Zend-Framework-104-PEAR-package-is-available</link>
    <guid isPermaLink="false">urn:md5:86aeb0f2eaf2c2f7b63fcc1f234ad94d</guid>
    <pubDate>Wed, 27 Feb 2008 11:17:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>package</category><category>pear</category><category>phpmafia</category><category>zend framework</category>    
    <description>    &lt;p&gt;The package for the last 1.0.x release, 1.0.4, is now available on the phpmafia pear channel. Please report any issue in the comment of this post. The Zend_Locale's xml bug should now be fixed (they are now considered as php and thus put at the &lt;em&gt;right&lt;/em&gt; place, which is not the best way to fix the bug I guess but at least it should work for now).&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/02/27/Zend-Framework-104-PEAR-package-is-available#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/02/27/Zend-Framework-104-PEAR-package-is-available#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1085</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.0.3 PEAR package</title>
    <link>http://fashion.hosmoz.net/post/2008/01/02/Zend-Framework-103-PEAR-package</link>
    <guid isPermaLink="false">urn:md5:89dd71f9a10d4805182d561de4012180</guid>
    <pubDate>Wed, 02 Jan 2008 23:50:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>package</category><category>pear</category><category>phpmafia</category><category>zend framework</category>    
    <description>    &lt;p&gt;Just to say I packaged the 1.0.3 version of the zend framework on the phpmafia pear channel. It's a bit late I know, but at least it's here. Please note that I already have been notified of a problem regarding the Zend Locale's xml datafiles and that I hope to have worked out a solution for the next release (1.5 if all goes well).&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/01/02/Zend-Framework-103-PEAR-package#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/01/02/Zend-Framework-103-PEAR-package#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1080</wfw:commentRss>
      </item>
    
  <item>
    <title>Accessing raw post data in a controller</title>
    <link>http://fashion.hosmoz.net/post/2007/11/21/Accessing-raw-post-data-in-a-controller</link>
    <guid isPermaLink="false">urn:md5:d8a3050d140c3d8fac1e1de762628c9d</guid>
    <pubDate>Wed, 21 Nov 2007 12:03:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>controller</category><category>http</category><category>post</category><category>raw post data</category><category>zend framework</category>    
    <description>    &lt;p&gt;For some reason, &lt;code&gt;$HTTP_RAW_POST_DATA&lt;/code&gt; does not seem to be set inside an action controller. You'll have to use the &lt;code&gt;php://input&lt;/code&gt; stream wrapper to access raw http post data:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$raw_post_data&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/file_get_contents&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_get_contents&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;'php://input'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/code&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/11/21/Accessing-raw-post-data-in-a-controller#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/11/21/Accessing-raw-post-data-in-a-controller#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1075</wfw:commentRss>
      </item>
    
  <item>
    <title>Extending Zend_Controller_Router_Route: the singleton problem.</title>
    <link>http://fashion.hosmoz.net/post/2007/11/05/Extending-Zend_Controller_Router_Route%3A-the-singleton-problem</link>
    <guid isPermaLink="false">urn:md5:639fef9d7c01edc0e63ee3f2c2a5c823</guid>
    <pubDate>Mon, 05 Nov 2007 14:37:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>annoying</category><category>dry</category><category>oop</category><category>pattern</category><category>php5</category><category>route</category><category>self</category><category>singleton</category><category>zend framework</category>    
    <description>    &lt;p&gt;Today I ran into an issue while extending &lt;code&gt;Zend_Controller_Router_Route&lt;/code&gt;. I wanted to add a little path pre/post processing in the &lt;code&gt;match()&lt;/code&gt; and &lt;code&gt;assemble()&lt;/code&gt; methods, so I just extended the Route class to add my tiny bits of code into the methods. Except it did not work at all. After a few debuging, it turned out that the Router uses &lt;code&gt;Zend_Controller_Router_Route::getInstance()&lt;/code&gt; to retrieve a route object, which uses a &lt;code&gt;new self();&lt;/code&gt; statement to instantiate the route object. Problem is that &lt;code&gt;self&lt;/code&gt; always refers to the current class definition we're in, if the method is called from a child class, without being overloaded, self will refer to the wrong class.&lt;/p&gt;


&lt;p&gt;Example:&lt;/p&gt;
&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; Foo &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public &lt;a href=&quot;http://www.php.net/static&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;static&lt;/span&gt;&lt;/a&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; getInstance&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; self;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;class&lt;/span&gt; Bar extends Foo &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.php.net/var_dump&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;var_dump&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;Bar::&lt;span style=&quot;color: #006600;&quot;&gt;getClass&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;/code&gt;


&lt;p&gt;echoes something like:&lt;/p&gt;

&lt;pre&gt;
object(Foo)#1 (0) {
}
&lt;/pre&gt;


&lt;p&gt;Which is fscking wrong IMHO. A quick workaround is to overload the &lt;code&gt;getInstance&lt;/code&gt; method, which is what I call pretty annoying as it does not follow the DRY principle.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/11/05/Extending-Zend_Controller_Router_Route%3A-the-singleton-problem#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/11/05/Extending-Zend_Controller_Router_Route%3A-the-singleton-problem#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1072</wfw:commentRss>
      </item>
    
  <item>
    <title>How I use the Zend Framework</title>
    <link>http://fashion.hosmoz.net/post/2007/10/16/How-I-use-the-Zend-Framework</link>
    <guid isPermaLink="false">urn:md5:15540fb9e20bbf5beef4ab8f8c6150ed</guid>
    <pubDate>Mon, 22 Oct 2007 13:39:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>application</category><category>architecture</category><category>conventions</category><category>models</category><category>modules</category><category>php</category><category>zend framework</category>    
    <description>&lt;p&gt;Having started a few applications using the Zend Framework, I came out with a few practices that I tend to use over and over. In this post I'll quickly expose some of them and explain why I do things the way I do them. As you'll notice, most of them are already widely known and used over the &lt;acronym&gt;ZF&lt;/acronym&gt; developer's community. Please remember that these practices are just &lt;em&gt;what I do&lt;/em&gt;, and come with no garanty at all to be &lt;em&gt;best practices&lt;/em&gt;.&lt;/p&gt;    &lt;h3&gt;Directory structure&lt;/h3&gt;


&lt;p&gt;First thing to work out when starting a new Zend Framework powered application, at least if you decide to use the &lt;acronym title=&quot;Zend Framework&quot;&gt;ZF&lt;/acronym&gt;'s &lt;acronym title=&quot;Model View Controller&quot;&gt;MVC&lt;/acronym&gt; component, is the application's directory structure. Here is the one I used, which is a slightly modified version of &lt;a href=&quot;http://framework.zend.com/manual/en/zend.controller.modular.html&quot;&gt;the official recommended structure&lt;/a&gt;. This is essentially a standard modular structure with all directories needed to store various additional data from your application.&lt;/p&gt;

&lt;pre&gt;
application/
	cache/
	config/
		application.ini
		routes.ini
	data/
	layouts/scripts/
	library/App/
	logs/
	modules/
		default/
		user/
document_root/
	css/
	images/
	index.php
	js/
&lt;/pre&gt;


&lt;p&gt;As you can see, I have many directories, each dedicated to a specific file type. This has many advantages, such as always knowing where to find what you're looking for or easily process files of a certain type (think &lt;code&gt;grep foo logs/*&lt;/code&gt;). Also, I name my directories explicitly. I used to call the &lt;code&gt;config&lt;/code&gt; directory &lt;code&gt;etc&lt;/code&gt;, which is the directory holding most configurations files under UNIX systems, but it may not appear that clear to non-UNIX user, while &lt;code&gt;config&lt;/code&gt; is clear enough for everyone.&lt;/p&gt;


&lt;p&gt;Another point you might notice is the that all applications files and data are placed outside the document_root. This is done to avoid unwanted access to such resources. While this is the best way, in my opinion, to do, it may not always be possible (like when you have no control on your actual &lt;code&gt;DocumentRoot&lt;/code&gt;. In this case, you may consider having the following structure:&lt;/p&gt;

&lt;pre&gt;
application/
	cache/
	config/
		application.ini
		routes.ini
	data/
	layouts/scripts/
	library/App/
	logs/
	modules/
		default/
		user/
	tasks/
css/
images/
index.php
js/
&lt;/pre&gt;


&lt;p&gt;Then you can deny any web access to the &lt;code&gt;application/&lt;/code&gt; directory with the following &lt;code&gt;htaccess&lt;/code&gt; rules:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;Directory application&amp;gt;
    Order allow,deny
    Deny from all
&amp;lt;/Directory&amp;gt;
&lt;/pre&gt;


&lt;h3&gt;Did you say modular ?&lt;/h3&gt;


&lt;p&gt;Yeah, I said it actually. Modules in Zend Framework are groups of controllers (along with their corresponding views and models) which sits in their own namespace. One could argue that module's primary goal is to ease code re-use, but I personnaly dunno, as I personnally still have not seen such a use of modules. The drawbacks of re-usable code is that it needs to be abstract enough to fit ant particular situation or so. In this context, I only have a single separate module alongside the default one: the user module. It has Index and Auth controllers, respectively used to perform &lt;acronym title=&quot;Create Read Update Delete&quot;&gt;CRUD&lt;/acronym&gt; and login/logout operations.&lt;/p&gt;


&lt;p&gt;Having re-usable modules implies that all modules containes its own models, or at least, knows where (ie, in which other module) to find its required models. There comes Xend's model loader. This is an action helper which ease the load of models inside controllers, like:&lt;/p&gt;

&lt;pre&gt;
$this-&amp;gt;_helper-&amp;gt;modelLoader(array('MyCoolModel', 'MyOtherModel'));
&lt;/pre&gt;


&lt;p&gt;Easy heh ? The bad point with this helper is that it is restricted to, or at best tricky to use outside, action controllers. That is why I developped my own library loader which I shall present in another blogpost soon.&lt;/p&gt;


&lt;h3&gt;Models naming convention&lt;/h3&gt;


&lt;p&gt;Using the &lt;a href=&quot;http://svn.ralphschindler.com/repo/Xend/&quot;&gt;Xend&lt;/a&gt;'s model loader trained me to adopt what I consider a good model naming convention, basically, it just follows the controller's conventions, that is, prefix the model name with the module's name, so that for example my user model is named like &lt;code&gt;User_Users&lt;/code&gt; (the first &lt;code&gt;User&lt;/code&gt; is the module name, the second &lt;code&gt;Users&lt;/code&gt; is the &lt;code&gt;ucfirst&lt;/code&gt;'ed tablename). whenever I need to have row specific model I just postfix the whole model name with &lt;code&gt;_Row&lt;/code&gt;. It gives the following directory architecture:&lt;/p&gt;

&lt;pre&gt;
modules/user/models/
	Users/Row.php
	Users.php
&lt;/pre&gt;


&lt;p&gt;I'll eventually load &lt;code&gt;User_Users_Row&lt;/code&gt; from &lt;code&gt;User/Users.php&lt;/code&gt; with a simple require:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;require_once&lt;/span&gt; &lt;a href=&quot;http://www.php.net/dirname&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;dirname&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;__FILE__&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;'/Users/Row.php'&lt;/span&gt;;&lt;/code&gt;


&lt;h3&gt;Personal library namespace&lt;/h3&gt;


&lt;p&gt;A recurring question from &lt;acronym&gt;ZF&lt;/acronym&gt; beginners is to know where they should put their own library classes. The answer is pretty simple actually. You just create your own library namespace alongside Zend's. Let's say you wish to extend &lt;code&gt;Zend_Db_Table_Abstract&lt;/code&gt; to add your own logic. The first thing to do is to choose the name of your namespace, we will use Foobar as an example, because this is a cool name. Your class will be named like &lt;code&gt;Foobar_Db_Table_Abstract&lt;/code&gt;, and located in &lt;code&gt;Foobar/Db/Table/Abstract.php&lt;/code&gt;, which in turn should be located anywhere in your &lt;code&gt;include_path&lt;/code&gt;. So you could have the following directory structure:&lt;/p&gt;

&lt;pre&gt;
application/library/
	Zend/
	Foobar/
	Riskle/
&lt;/pre&gt;


&lt;p&gt;Just remember &lt;acronym&gt;ZF&lt;/acronym&gt;'s naming convention: from the filename, strip the &lt;code&gt;.php&lt;/code&gt;, replace slashes (/) with underscores (_), and you've got the class name. Simple heh ?&lt;/p&gt;


&lt;h3&gt;App_ library namespace (App_Controller_Action, etc)&lt;/h3&gt;


&lt;p&gt;Additionnaly to my personal library namespace, I also have a special &lt;code&gt;App&lt;/code&gt; namespace, which I always locate into &lt;code&gt;application/library/App&lt;/code&gt;. This namespace principally provides two classes, &lt;code&gt;App_Controller_Action&lt;/code&gt; and &lt;code&gt;App_Db_Table_Abstract&lt;/code&gt;, which basically extend respectively &lt;code&gt;Zend_Controller_Action&lt;/code&gt; and &lt;code&gt;Zend_Db_Table_Abstract&lt;/code&gt;. All my controllers and models then use the &lt;code&gt;App_&lt;/code&gt; namespace as a reference, so that I can easily change the base class for all my controllers / models as easily as changing the parent of the corresponding &lt;code&gt;App&lt;/code&gt; class.&lt;/p&gt;


&lt;h3&gt;Using third party components&lt;/h3&gt;


&lt;p&gt;Using &lt;acronym&gt;ZF&lt;/acronym&gt; compatible components is just easy as dropping them in your include path. By &lt;acronym&gt;ZF&lt;/acronym&gt; compatible, I mean following the &lt;acronym&gt;ZF&lt;/acronym&gt; class naming convention. Just make source it's in your &lt;code&gt;include_path&lt;/code&gt;, and you can start using them right away. Components library I use includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://svn.ralphschindler.com/repo/Xend/&quot;&gt;Xend&lt;/a&gt;'s layout component&lt;/li&gt;
&lt;li&gt;Some components from &lt;a href=&quot;http://tools.assembla.com/svn/naneau_zf/library/Naneau/&quot;&gt;Naneau's library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;My own library, &lt;a href=&quot;http://tools.assembla.com/svn/riskle/library/Riskle/&quot;&gt;Riskle&lt;/a&gt; (you'll need an &lt;a href=&quot;http://www.assembla.com/&quot;&gt;assembla&lt;/a&gt; account)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I put them in a particular path (&lt;code&gt;~/share/php/&lt;/code&gt;) which I add to my include path.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;note&lt;/strong&gt;: Some &lt;a href=&quot;http://naneau.nl/&quot;&gt;dikdiks&lt;/a&gt; tend to store third-party in &lt;code&gt;application/library/&lt;/code&gt; instead of a completely separate place. This problem looks a lot like dynamically linked vs static binaries. With static binaries (in our case, storing all in &lt;code&gt;application/library/&lt;/code&gt;), you don't have to care about dependencies, as every single needed line of code is shipped with your application. This ease redistribution and installation a lot, but makes your download larger. You also have to manage yourself dependencies upgrade (which in turn save this hassle from the end-user). With dynamically linked applications, you avoid duplicated code by forcing the use of a global, site wide, code repository (generally &lt;code&gt;/usr/share/php&lt;/code&gt; on unix systems). You also transfer dependencies handling to the end-user (and/or the packaging system). Really, this is a choice to make yourself I think.&lt;/p&gt;


&lt;p&gt;Things get a little bit more complicated when the components does not follow the naming convention. What I do in this case is just puting them into a separate directory tree called &lt;code&gt;vendor/&lt;/code&gt;, which I don't forget to add to my include path of course, then I just manually includes need files. We could have done a one-to-one match between the component's public classes and custom &lt;em&gt;well-named&lt;/em&gt; classes, but it's much of a hassle for the benefit I think.&lt;/p&gt;


&lt;h3&gt;That's all folks !&lt;/h3&gt;

&lt;p&gt;Well that's all for today. I'll try to write some more in the future about application building with the Zend Framework, there are still a lot of things to be said, invented, and discovered :-)&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/10/16/How-I-use-the-Zend-Framework#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/10/16/How-I-use-the-Zend-Framework#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1070</wfw:commentRss>
      </item>
    
  <item>
    <title>New home for pagination component documentation</title>
    <link>http://fashion.hosmoz.net/post/2007/10/01/New-for-pagination-component-documentation</link>
    <guid isPermaLink="false">urn:md5:f869594140e39681b3570bda870b75ed</guid>
    <pubDate>Mon, 01 Oct 2007 12:44:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>assembla</category><category>pagination</category><category>php</category><category>riskle</category><category>zend framework</category>    
    <description>    &lt;p&gt;For those caring, I just posted some quick documentation for &lt;a href=&quot;http://www.assembla.com/wiki/show/riskle/Pagination_Component&quot;&gt;the pagination component at my assembla space&lt;/a&gt;. More docs will follow (including extensive phpdoc docblocks I hope).&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/10/01/New-for-pagination-component-documentation#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/10/01/New-for-pagination-component-documentation#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1053</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.0.2 PEAR package is available</title>
    <link>http://fashion.hosmoz.net/post/2007/09/30/Zend-Framework-102-PEAR-package-is-available</link>
    <guid isPermaLink="false">urn:md5:06df36675496a157c1aff50b1a4f36e7</guid>
    <pubDate>Sun, 30 Sep 2007 16:21:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>package</category><category>pear</category><category>php</category><category>zend framework</category>    
    <description>    &lt;p&gt;A PEAR package for the 1.0.2 version of the Zend Framework is now available from &lt;a href=&quot;http://pear.phpmafia.net/&quot;&gt;the PEAR PHPMafia channel&lt;/a&gt;. As usual, to install just issue the following:&lt;/p&gt;

&lt;code class=&quot;bash&quot;&gt;pear channel-discover pear.phpmafia.net&lt;br /&gt;
pear install phpmafia/Zend&lt;/code&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/09/30/Zend-Framework-102-PEAR-package-is-available#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/09/30/Zend-Framework-102-PEAR-package-is-available#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1051</wfw:commentRss>
      </item>
    
  <item>
    <title>Bugfixes release of Zend Framework pagination component</title>
    <link>http://fashion.hosmoz.net/post/2007/09/30/Bugfixes-release-of-Zend-Framework-pagination-component</link>
    <guid isPermaLink="false">urn:md5:bf8dcb74b43de25d55ba962423b5a74b</guid>
    <pubDate>Sun, 30 Sep 2007 01:28:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>assembla</category><category>pagination</category><category>php</category><category>riskle</category><category>zend framework</category><category>zend_db_table</category>    
    <description>    &lt;p&gt;I just released on &lt;a href=&quot;http://www.assembla.com/wiki/show/riskle&quot;&gt;riskle's assembla space&lt;/a&gt; a new version of my &lt;a href=&quot;http://www.assembla.com/wiki/show/riskle/Pagination_Component&quot;&gt;pagination component for the Zend Framework&lt;/a&gt; which you can download right now:&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://fashion.hosmoz.net/public/paginate-r122.tgz&quot;&gt;Riskle Paginate r122&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;This release fixes a nasty bug in &lt;code&gt;Riskle_Db_Table::fetchCols&lt;/code&gt; which prevented from retrieving the right count of cols involved in the query.&lt;/p&gt;


&lt;p&gt;The table component has also been slightly rewritten following &lt;a href=&quot;http://fashion.hosmoz.net/post/2007/09/23/Zend-Framework-Pagination-third-strike#c6892&quot;&gt;Erik's suggestion&lt;/a&gt; to move the parent mapping into &lt;code&gt;_fetch&lt;/code&gt;. The parent mapping itself has been improved to allow &amp;quot;multi level&amp;quot; table joining. This will be best explained with an example:&lt;/p&gt;


&lt;p&gt;Say you have three table, Foo, Bar and Quux, and you would like to execute the following query:&lt;/p&gt;

&lt;code class=&quot;sql&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SELECT&lt;/span&gt; * &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;FROM&lt;/span&gt; Foo &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;JOIN&lt;/span&gt; Bar &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;ON&lt;/span&gt; Foo.bar_id = Bar.id &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;JOIN&lt;/span&gt; Quux &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;ON&lt;/span&gt; Bar.quux_id = Quux.id&lt;/code&gt;


&lt;p&gt;This is now possible with the following mapping (in Foo's class of course):&lt;/p&gt;

&lt;code class=&quot;php&quot;&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;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Bar'&lt;/span&gt; =&amp;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;'local'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'bar_id'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'remote'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'id'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Quux'&lt;/span&gt; =&amp;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;'local'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'quux_id'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'remote'&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;'Quux.id'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/code&gt;


&lt;p&gt;Easy heh ?&lt;/p&gt;


&lt;p&gt;As usual, any comments are appreciated, and please note that this code is released under the same license as the ZF itself, &lt;a href=&quot;http://framework.zend.com/license&quot;&gt;the new-bsd license&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/09/30/Bugfixes-release-of-Zend-Framework-pagination-component#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/09/30/Bugfixes-release-of-Zend-Framework-pagination-component#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1050</wfw:commentRss>
      </item>
    
  <item>
    <title>Of controller plugins and directory layout</title>
    <link>http://fashion.hosmoz.net/post/2007/09/22/A-word-on-controller-plugins</link>
    <guid isPermaLink="false">urn:md5:efefaa9aeeee587e18314a690c4ac04a</guid>
    <pubDate>Sun, 23 Sep 2007 00:55:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>controllers</category><category>directory layout</category><category>modules</category><category>plugins</category><category>zend framework</category>    
    <description>    &lt;p&gt;When anyone on #zftalk ask about where controller plugins should be kept, we usually responds something like &lt;em&gt;have your own library namesapce alongside Zend/ and put it in it like &lt;code&gt;YourNamespace/Controller/Plugin/YourPlugin.php&lt;/code&gt;&lt;/em&gt;. But what about application specific controllers ? There's a time where you have to write a plugin that relies on the application at such a level that using it elsewhere would make no sense. In that case, where can we store this plugin ? The question arised this morning, and we ended up to the fact that having a controller-level plugin directory would not hurt, after all. So one could have the following directory layout (simplified on purpose):&lt;/p&gt;

&lt;pre&gt;
/application/modules/default
    /controllers
    /library/Plugin
        MyPlugin.php
&lt;/pre&gt;


&lt;p&gt;The drawback is that in order to use autoload you would have to have each modules &lt;code&gt;Plugin&lt;/code&gt; dir in the include path, which is a bit of a hassle. Instead, we could have the much more simple folloing layout:&lt;/p&gt;

&lt;pre&gt;
/application
    library/Controller/Plugin
        MyPlugin.php
&lt;/pre&gt;


&lt;p&gt;Which is simpler but does not allow for modules specific plugins. Anyway, the former layout would require a bit more logic in the bootstrap in order to extract every modules path as plugins are registered pre-dispatch.&lt;/p&gt;


&lt;p&gt;Hope it helps with directory layout organization :-)&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;What I've finally decided to do is the following:&lt;/p&gt;

&lt;pre&gt;
/application
    library/App/Controller/Plugin
        MyPlugin.php
&lt;/pre&gt;


&lt;p&gt;So that application specific code gets prefixed with the &lt;code&gt;App_&lt;/code&gt; namespace.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/09/22/A-word-on-controller-plugins#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/09/22/A-word-on-controller-plugins#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1038</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework Pagination, third strike</title>
    <link>http://fashion.hosmoz.net/post/2007/09/23/Zend-Framework-Pagination-third-strike</link>
    <guid isPermaLink="false">urn:md5:cd71ba5fa11c55c1e297ea7462563b80</guid>
    <pubDate>Sun, 23 Sep 2007 00:07:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>assembla</category><category>pagination</category><category>php</category><category>riskle</category><category>zend framework</category><category>zend_db_table</category>    
    <description>    &lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: &lt;a href=&quot;http://fashion.hosmoz.net/post/2007/09/30/Bugfixes-release-of-Zend-Framework-pagination-component&quot;&gt;new version (r105) available&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;The component was given a little rewrite as expected, but maybe a little bit later than I would have wanted to :-) So it now has its own Rowclass proxy from which you can pull various infos such as current page, page range, next page, etc all exposed as getter methods (that is, &lt;code&gt;getCurrentPage&lt;/code&gt;, &lt;code&gt;getPageRange&lt;/code&gt;, &lt;code&gt;getNextPage&lt;/code&gt;, etc), which you won't really have to worry about since the brand new view helper will take care of that for you. Usage has changed a little, bit, so let's first have a look at what's happening from the controller point of view:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$table&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Riskle_Db_Table_Paginate&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Table, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_getParam&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'page'&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;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;view&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;rowset&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$table&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fetchAll&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;/code&gt;


&lt;p&gt;Not much changed here, except we don't need anymore to call &lt;code&gt;getPaginationInfos()&lt;/code&gt;. Nice ! Now the big part, the view:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;paginate&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;rowset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&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;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;paginate&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;previous&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;br /&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;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;paginate&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;navigation&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;br /&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;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;paginate&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;next&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;/code&gt;


&lt;p&gt;The view helper uses the neat &lt;a href=&quot;http://naneau.nl/2007/09/18/the-magic-of-view-helpers/&quot;&gt;composite helper trick from naneau&lt;/a&gt; - which is a really cool trick, great job naneau my fellow no-more-a-bunny. The first call inits the helper, feeding him the necessary rowset to work on, then you just have to call the methods you need to draw the navigation links. As you may expect, &lt;code&gt;previous&lt;/code&gt; and &lt;code&gt;next&lt;/code&gt; method will return nothing if no page is available (actually, they return their second argument, which defaults to an empty string).&lt;/p&gt;


&lt;p&gt;Also, it's worth noting that the bundled &lt;code&gt;Riskle_Db_Table&lt;/code&gt; features &lt;a href=&quot;http://fashion.hosmoz.net/post/2007/07/31/Zend_Db_Table-and-tables-relationships#c6428&quot;&gt;the patch from Erik&lt;/a&gt;, as well as a totally rewritten &lt;code&gt;fetchCols&lt;/code&gt; method (now uses a straight &lt;code&gt;Zend_Db_Select&lt;/code&gt; object instead of the ugly trick it used to use).&lt;/p&gt;


&lt;p&gt;My code is no longer available on subversion, I moved the &lt;em&gt;project&lt;/em&gt; to &lt;a href=&quot;http://www.assembla.com/&quot;&gt;assembla&lt;/a&gt;. Instead ou can download this component from the &lt;a href=&quot;http://www.assembla.com/spaces/files/riskle&quot;&gt;riskle space's files board&lt;/a&gt; (&lt;a href=&quot;http://www.assembla.com/spaces/get_file_by_id/bbKtMAAvGr3j8OabIlDkbG&quot;&gt;direct download&lt;/a&gt;), the file contains all classes needed for the component to work, just unzip it in your include_path and you're set.&lt;/p&gt;


&lt;p&gt;As usual, any comments are more than welcome.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/09/23/Zend-Framework-Pagination-third-strike#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/09/23/Zend-Framework-Pagination-third-strike#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1039</wfw:commentRss>
      </item>
    
  <item>
    <title>Riskle_Form, a quick wrapup</title>
    <link>http://fashion.hosmoz.net/post/2007/09/19/Riskle_Form-a-quick-wrapup</link>
    <guid isPermaLink="false">urn:md5:ff12feb0814ef1c75f90d325740e7c31</guid>
    <pubDate>Wed, 19 Sep 2007 16:12:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>php</category><category>riskle_form</category><category>zend framework</category>    
    <description>&lt;p&gt;So well, I've been busy these days working on my own implementation of a form component in the &lt;acronym&gt;ZF&lt;/acronym&gt; spirit. This post is to help me see where I'm at with this component, as well as planning future evolution. I'll try my best to describe what it does and does not, and what it could do in the future.&lt;/p&gt;


&lt;p&gt;Of course, while this is more of a personnal &lt;em&gt;pense-bete&lt;/em&gt; than anything else, any comments are welcome.&lt;/p&gt;    &lt;h3&gt;Basic features&lt;/h3&gt;


&lt;p&gt;Forms are build using the factory, which ensures each form has a unique name so that two forms can't conflict when used on the same action. Each element of the form is materialized by an instance of &lt;code&gt;Riskle_Form_Element&lt;/code&gt; which holds any configuration directive for the element.&lt;/p&gt;


&lt;h3&gt;Prototyping&lt;/h3&gt;


&lt;p&gt;The component features an extensible prototyping system via the &lt;code&gt;Riskle_Form_Prototype&lt;/code&gt; set of class. Default (and mandatory atm) is to use a &lt;code&gt;Zend_Config_Ini&lt;/code&gt; file which can in turn contains further prototyping instructions, such as prototype from a model (by model I mean a class extending &lt;code&gt;Zend_Db_Table&lt;/code&gt;). A given form can embed multiple prototypes, possibly of the same type, which have to be &lt;em&gt;conretized&lt;/em&gt; before the form is usable. Concretization of form operates in a &lt;acronym title=&quot;First In Last Out&quot;&gt;FILO&lt;/acronym&gt; merging fashion. Prototyping from a model is for the moment very basic, it treats all fields as text field, but this will be addressed in time. Of course, the system allows for different source of prototyping (think &lt;code&gt;Riskle_Form_Prototype_Xml&lt;/code&gt; for example).&lt;/p&gt;


&lt;h3&gt;Form elements&lt;/h3&gt;


&lt;p&gt;Elements features a variety of configuration directives, which I'll details here.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;type&lt;/strong&gt;: explicitly tells the type of the field (for the moment, better tell an existing &lt;acronym&gt;HTML&lt;/acronym&gt; type). default is &lt;code&gt;text&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;label&lt;/strong&gt;: basically, the string to be put into the &amp;lt;label /&amp;gt; tag.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;validators&lt;/strong&gt;: an array of validators, see &lt;em&gt;Data validation&lt;/em&gt; for details.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;allow_empty&lt;/strong&gt;: weither the field is allowed to be empty or not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;datasource&lt;/strong&gt;: specify a datasource to retrieve the field datas from (only used for &amp;lt;select /&amp;gt; fields). See below for further details about that.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;depends&lt;/strong&gt;: specify a field to which the current field is dependent. Mainly used for auto-ajax-refreshing &amp;lt;select /&amp;gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The &lt;em&gt;datasource&lt;/em&gt; directive deserves a little more explanation. When the form factory encounters a datasource directive, it delegates the work to the datasource factory, which autodetects and decode the datasource. The core distributions handles the following datasources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instanciated Model, with format: &lt;code&gt;YourModel-&amp;gt;method&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Static Model, with format: &lt;code&gt;YourModel::method&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;acronym&gt;CSV&lt;/acronym&gt; string, with format: &lt;code&gt;csv:foo,bar&lt;/code&gt;. It uses a user land &lt;acronym&gt;CSV&lt;/acronym&gt; decoder that will most likely be bundled with the core distribution when (if ?) released.&lt;/li&gt;
&lt;li&gt;&lt;acronym&gt;JSON&lt;/acronym&gt; string, with format: &lt;code&gt;json:{'foo', 'bar'}&lt;/code&gt;. It's worth noting that this example will be converted to the following associating array: &lt;code&gt;array('foo' =&amp;gt; 'foo', 'bar' =&amp;gt; 'bar')&lt;/code&gt;. You can avoid this by including a noassoc switch (so that it reads &lt;code&gt;json:noassoc:{'foo', 'bar'}&lt;/code&gt;. Another note on &lt;acronym&gt;JSON&lt;/acronym&gt;: the main problem when allowing &lt;acronym&gt;JSON&lt;/acronym&gt; in INI files is that you can't have a double quote character in values (except by using a dirty hack which I do not want), and the php json decoder expects identifiers to be doublequoted. The datasource handles this by replacing any non escaped single quote to a double quote.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Data validation&lt;/h3&gt;


&lt;p&gt;Data validation is done by a subclassed &lt;code&gt;Zend_Input_Filter&lt;/code&gt;. &lt;code&gt;validators&lt;/code&gt; configuration from elements should conform to &lt;acronym&gt;ZFI&lt;/acronym&gt; syntax. The custom &lt;code&gt;Riskle_Form_Input&lt;/code&gt; component features a &lt;code&gt;getRaw&lt;/code&gt; set of methods to retrieve raw data (used in case the form was not successful). Not much else to say here.&lt;/p&gt;


&lt;h3&gt;Rendering&lt;/h3&gt;


&lt;p&gt;The core distribution features a set of view helper aimed at easing html form drawing. The helpers use the built-in ZF view helpers to render fields while adding a bunch of custom markup around (namely: labels and error messages). The default helpers also take care of fields that depend on other fields (see &lt;em&gt;Form elements&lt;/em&gt;) and add the according ajax queries to populate the element.&lt;/p&gt;


&lt;h3&gt;Workflow control&lt;/h3&gt;


&lt;p&gt;The most interesting part I think. &lt;code&gt;Riskle_Form&lt;/code&gt; features a plugin system, much like the &lt;code&gt;Zend_Controller&lt;/code&gt; one. It exposes the following hooks (in this order):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;formStartup&lt;/code&gt;, always run at the beginning of the workflow&lt;/li&gt;
&lt;li&gt;&lt;code&gt;prePopulate&lt;/code&gt;, run before the form gets it data (either from the model or the request)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;postPopulate&lt;/code&gt;, run after the form gets it data&lt;/li&gt;
&lt;li&gt;&lt;code&gt;preValidate&lt;/code&gt;, run before the forms attempts to validate the data&lt;/li&gt;
&lt;li&gt;&lt;code&gt;onValidateSuccess&lt;/code&gt;, run if and only if the data validation was a success&lt;/li&gt;
&lt;li&gt;&lt;code&gt;onValidateFailure&lt;/code&gt;, run if and only if the data validation was a failure&lt;/li&gt;
&lt;li&gt;&lt;code&gt;postValidate&lt;/code&gt;, run after the forms attempts to validate the data (regardless of the success or not)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;preCommit&lt;/code&gt;, run before the form tries to feed the model with the data&lt;/li&gt;
&lt;li&gt;&lt;code&gt;onCommitSuccess&lt;/code&gt;, run if and only if the data feedage was a success&lt;/li&gt;
&lt;li&gt;&lt;code&gt;onCommitFailure&lt;/code&gt;, run if and only if the data feedage was a failure&lt;/li&gt;
&lt;li&gt;&lt;code&gt;postCommit&lt;/code&gt;, run after the forms tries to feed the model with the data (regardless of the success or not)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;formShutdown&lt;/code&gt;, always run at the end of the workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each hook, the instance of the current form is passed as an argument to the method. Of course, the &lt;em&gt;commit&lt;/em&gt; set of hooks will only be run if the data validates.&lt;/p&gt;


&lt;h3&gt;Sample usage&lt;/h3&gt;


&lt;p&gt;A simple uploading form could look like the following:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt; = Riskle_Form::&lt;span style=&quot;color: #006600;&quot;&gt;factory&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Zend_Config_Ini&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'upload.ini'&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;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;registerPlugin&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Riskle_Form_Plugin_Upload&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'myUploadField'&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;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;run&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;br /&gt;
&lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;view&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;assign&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'form'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$form&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/code&gt;


&lt;p&gt;the view would look like:&lt;/p&gt;

&lt;pre&gt;
echo $this-&amp;gt;drawForm($this-&amp;gt;form);
&lt;/pre&gt;


&lt;p&gt;and &lt;code&gt;upload.ini&lt;/code&gt; could look like:&lt;/p&gt;

&lt;code class=&quot;ini&quot;&gt;&lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;&lt;span style=&quot;&quot;&gt;&amp;#91;&lt;/span&gt;form&lt;span style=&quot;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000099;&quot;&gt;model &lt;/span&gt;= &lt;span style=&quot;color: #933;&quot;&gt;&amp;quot;uploaded_files&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #000099;&quot;&gt;prototype &lt;/span&gt;=&lt;span style=&quot;color: #660066;&quot;&gt; &lt;span style=&quot;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #000066; font-weight:bold;&quot;&gt;&lt;span style=&quot;&quot;&gt;&amp;#91;&lt;/span&gt;fields&lt;span style=&quot;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
myUploadField.&lt;span style=&quot;color: #000099;&quot;&gt;type &lt;/span&gt;= &lt;span style=&quot;color: #933;&quot;&gt;&amp;quot;file&amp;quot;&lt;/span&gt;&lt;br /&gt;
myUploadField.&lt;span style=&quot;color: #000099;&quot;&gt;label &lt;/span&gt;= &lt;span style=&quot;color: #933;&quot;&gt;&amp;quot;choose an image&amp;quot;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
legend.&lt;span style=&quot;color: #000099;&quot;&gt;type &lt;/span&gt;= &lt;span style=&quot;color: #933;&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;br /&gt;
legend.&lt;span style=&quot;color: #000099;&quot;&gt;label &lt;/span&gt;= &lt;span style=&quot;color: #933;&quot;&gt;&amp;quot;Legend&amp;quot;&lt;/span&gt;&lt;/code&gt;


&lt;h3&gt;What it lacks&lt;/h3&gt;


&lt;p&gt;Clearly, this form component is designed for use in an HTML component. Few or no care has been taken to ensure cross-medium compatibiliy such as XHTML, PDF, etc. Hopefully the changes to apply to achieve such compatibility will not be that much of a hassle. While I'm not willing to ensure such a compatibility, I'd be happy to apply any patch submitted.&lt;/p&gt;


&lt;p&gt;Regarding plugins, they still miss the ability to really act on the workflow, such as stopping it, skipping steps (?) or add errors to the stack, etc.&lt;/p&gt;


&lt;p&gt;Also, the code still needs a few refactoring and optimization, especially regarding the view helpers and the main form class, as well as the configuration file syntax which needs an in-depth revision.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/09/19/Riskle_Form-a-quick-wrapup#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/09/19/Riskle_Form-a-quick-wrapup#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1033</wfw:commentRss>
      </item>
    
  <item>
    <title>findBy{$Field} with Zend_Db_Table</title>
    <link>http://fashion.hosmoz.net/post/2007/08/14/findByField-with-Zend_Db_Table</link>
    <guid isPermaLink="false">urn:md5:edc7726e6c6eb1caa3016b7d7cb764b8</guid>
    <pubDate>Tue, 14 Aug 2007 14:01:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>__call</category><category>php</category><category>zend framework</category><category>zend_db_table</category>    
    <description>    &lt;p&gt;A quick post to show how one can easily implement a &lt;em&gt;findByField&lt;/em&gt; wrapper in &lt;code&gt;Zend_Db_Table&lt;/code&gt;:&lt;/p&gt;

&lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * Implements a simple findByField wrapper&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; */&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; __call&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$method&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$args&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/preg_match&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_match&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;'/^findBy([a-zA-Z0-9]+)$/'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$method&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$parts&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$field&lt;/span&gt; = &lt;a href=&quot;http://www.php.net/strtolower&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;strtolower&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/preg_replace&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;preg_replace&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;'/([a-z])([A-Z])/'&lt;/span&gt;, &lt;span style=&quot;color: #ff0000;&quot;&gt;'$1_$2'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$parts&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&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: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/in_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;in_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;$field&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_cols&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;new&lt;/span&gt; Zend_Db_Table_Exception&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/sprintf&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;sprintf&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;'&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt;%s&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\'&lt;/span&gt; field not in row'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$field&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&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;getAdapter&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$where&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteInto&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteIdentifier&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$field&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;' = ?'&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$args&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&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;fetchAll&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$where&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;What it does is basically trapping any non-existant method call and check if the corresponding field exists, after converting &lt;em&gt;CamelCasing&lt;/em&gt; to &lt;em&gt;underscore_notation&lt;/em&gt; (eg: &lt;em&gt;FooBar&lt;/em&gt; becomes &lt;em&gt;foo_bar&lt;/em&gt;).&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/08/14/findByField-with-Zend_Db_Table#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/08/14/findByField-with-Zend_Db_Table#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/928</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend_Db_Table and tables relationships</title>
    <link>http://fashion.hosmoz.net/post/2007/07/31/Zend_Db_Table-and-tables-relationships</link>
    <guid isPermaLink="false">urn:md5:507bd82c9b3cc58c0603ca2e1a362245</guid>
    <pubDate>Mon, 13 Aug 2007 15:39:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>join</category><category>relationships</category><category>zend framework</category><category>zend_db_table</category>    
    <description>&lt;p&gt;When developping a database tied application, you eventually come to a point where you get (at least) two tables with a parent/child relationship, such as for example a &lt;code&gt;User&lt;/code&gt; table referenced by, say, a &lt;code&gt;Post&lt;/code&gt; table (each post belonging to a specific user). That's basically the point where you need &lt;a href=&quot;http://framework.zend.com/manual/en/zend.db.table.relationships.html&quot;&gt;Zend_Db_Table relationships mechanism&lt;/a&gt;. the drawback of this mechanism is that, as far as I know, it does not produce joined queries to retrieve the parent data, but fires a query for each parent row. Thus instead of just using Zend_Db Relationships, I developped a simple yet effective auto-join mechanism that I called, in great simplicity, &lt;em&gt;parent mapping&lt;/em&gt;. It supports multiple joins from multiple tables, remote fields specification and prefixing.&lt;/p&gt;


&lt;p&gt;It is included in my &lt;a href=&quot;http://tools.assembla.com/svn/riskle/library/Riskle/Db/Table.php&quot;&gt;db table class&lt;/a&gt; and you can see the interesting part of the code below for your convenience (Ignore the 3 first lines of the function as it is used for something else in my version of the framework).&lt;/p&gt;    &lt;code class=&quot;php&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * Holds the parent mapping for join in fetchAll&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; *&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;lt;code&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * array(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp;'remote_table' =&amp;gt; array(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;'remote' =&amp;gt; 'id'&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;'local' =&amp;gt; 'remote_id',&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;'fields' =&amp;gt; array('foo', 'bar', 'prefix' =&amp;gt; 'remote_'),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;nbsp; &amp;nbsp; &amp;nbsp;),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * );&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * &amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; *&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @var array&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; */&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; protected &lt;span style=&quot;color: #0000ff;&quot;&gt;$_parentMap&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: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * Honors the parent mapping from self::_parentMap&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; *&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @param string|array $where&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @param string|array $order&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @param integer $count&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @param integer $offset&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; * @return Zend_Db_Table_Rowset&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; */&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; fetchAll&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$where&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$order&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$count&lt;/span&gt; = &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$offset&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;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/is_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_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;$this&lt;/span&gt;-&amp;gt;_cols&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; parent::&lt;span style=&quot;color: #006600;&quot;&gt;fetchAll&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$where&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$order&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$count&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$offset&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&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;getAdapter&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$select&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&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: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$select&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: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_name, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_cols, &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_schema&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;order&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$order&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&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: #0000ff;&quot;&gt;$offset&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/is_null&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_null&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;$where&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$select&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: #0000ff;&quot;&gt;$where&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/empty&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;empty&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;-&amp;gt;_parentMap&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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;$this&lt;/span&gt;-&amp;gt;_parentMap &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$parentTable&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$specs&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$fields&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: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fields'&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;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'prefix'&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: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$prefix&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fields'&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;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'prefix'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fields'&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;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'prefix'&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fields'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt; =&amp;gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$field&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &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/is_int&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_int&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;$key&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$prefix&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$field&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$field&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$fields&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'fields'&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$select&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;join&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$parentTable&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://www.php.net/sprintf&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;sprintf&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;'%s.%s = %s.%s'&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteIdentifier&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;_name&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteIdentifier&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'local'&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteIdentifier&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$parentTable&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;quoteIdentifier&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$specs&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;'remote'&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;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$fields&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #0000ff;&quot;&gt;$stmt&lt;/span&gt; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$db&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$select&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$this&lt;/span&gt;-&amp;gt;_makeRowset&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$stmt&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/31/Zend_Db_Table-and-tables-relationships#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/31/Zend_Db_Table-and-tables-relationships#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/910</wfw:commentRss>
      </item>
    
  <item>
    <title>Stripping the logic: the Transfer Object</title>
    <link>http://fashion.hosmoz.net/post/2007/08/11/Stripping-the-logic%3A-the-Transfert-Object</link>
    <guid isPermaLink="false">urn:md5:fb705efad8749c9d2c20f85702147c29</guid>
    <pubDate>Sat, 11 Aug 2007 11:56:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>j2ee</category><category>oop</category><category>p of eaa</category><category>pattern</category><category>php</category><category>transfer object</category><category>zend framework</category>    
    <description>    &lt;p&gt;Sometimes you have to pass an object data to another object, or to another layer of your application (who said controller/view ?), while ensuring that the receiving entity will not be able to run business code encapsulated in your class. In the Zend Framework, several objects provide a &lt;code&gt;toArray&lt;/code&gt; method, but that is not always sufficient as sometimes you'd like to keep with the &lt;code&gt;$object-&amp;gt;varname&lt;/code&gt; syntax.&lt;/p&gt;


&lt;p&gt;That is where the Transfer Object arrives. While the preceding definition is not exact (that's not the real purpose of the Transfert Object in the J2EE spirit), This is the most common use that PHP Developers can make of it nowadays I think. So I came up with a &lt;a href=&quot;http://svn.riskle.com/library/Riskle/Pattern/TransferObject.php&quot;&gt;very light implementation of a concept&lt;/a&gt; which I hope can prove useful for any folks getting by there.&lt;/p&gt;


&lt;p&gt;See also:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Martin Fowler's &lt;a href=&quot;http://www.martinfowler.com/eaaCatalog/valueObject.html&quot;&gt;Value Object&lt;/a&gt; and &lt;a href=&quot;http://www.martinfowler.com/eaaCatalog/dataTransferObject.html&quot;&gt;Data Transfer Object&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html&quot;&gt;The Transfert Object as a Core J2EE Pattern&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/08/11/Stripping-the-logic%3A-the-Transfert-Object#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/08/11/Stripping-the-logic%3A-the-Transfert-Object#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/925</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework Pagination reloaded</title>
    <link>http://fashion.hosmoz.net/post/2007/07/31/Zend-Framework-Pagination-reloaded</link>
    <guid isPermaLink="false">urn:md5:ff2795a69d87c7651a3e739a14720d82</guid>
    <pubDate>Tue, 31 Jul 2007 11:33:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>pagination</category><category>pattern</category><category>php</category><category>proxy</category><category>zend framework</category><category>zend_db_table</category>    
    <description>    &lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://fashion.hosmoz.net/post/2007/09/23/Zend-Framework-Pagination-third-strike&quot;&gt;A new version of this component is available&lt;/a&gt;.&lt;/p&gt;



&lt;p&gt;I have a &lt;a href=&quot;http://svn.riskle.com/library/Riskle/Db/Table/Paginate.php&quot;&gt;new version of my pagination component&lt;/a&gt; which solve &lt;a href=&quot;http://fashion.hosmoz.net/post/2007/07/15/Pagination-with-the-Zend-Framework#c2757&quot;&gt;the issue previously pointed out&lt;/a&gt; by &lt;a href=&quot;http://totalement.geek.oupas.fr/&quot;&gt;Guy&lt;/a&gt;. This update comes along with &lt;a href=&quot;http://svn.riskle.com/library/Riskle/Db/Table.php&quot;&gt;a subclassed version of Zend_Db_Table&lt;/a&gt; which allows counting and specific columns selection respectively via the &lt;code&gt;fetchCount()&lt;/code&gt; and &lt;code&gt;fetchCols()&lt;/code&gt; methods. Btw, the &lt;code&gt;fetchCols()&lt;/code&gt; method is &lt;strong&gt;very&lt;/strong&gt; hackish at the moment, and I'll certainly end up with rewriting it using a plain &lt;code&gt;Zend_Db_Select&lt;/code&gt; statement.&lt;/p&gt;


&lt;p&gt;As always, any comment is appreciated. I'm thinking of subclassing the Rowset class to fill it with pagination info getters like &lt;code&gt;getPageCount()&lt;/code&gt;, &lt;code&gt;getNextPage()&lt;/code&gt;, etc, like in &lt;em&gt;Symfony&lt;/em&gt; for those knowing, instead of relying on a &lt;code&gt;getPaginationInfo()&lt;/code&gt; method. Future improvements will also include more view helper magic.&lt;/p&gt;


&lt;p&gt;Also, I came up with a small new &lt;code&gt;Riskle_Pattern&lt;/code&gt; namespace which I use to &lt;a href=&quot;http://svn.riskle.com/library/Riskle/Pattern/Proxy.php&quot;&gt;implement commonly used patterns&lt;/a&gt;, such as the &lt;a href=&quot;http://en.wikipedia.org/wiki/Proxy_pattern&quot;&gt;Proxy Pattern&lt;/a&gt;. I'm not yet sure of the pertinence of this thing, so any comments are yet again very much appreciated on this topic :-)&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/31/Zend-Framework-Pagination-reloaded#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/31/Zend-Framework-Pagination-reloaded#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/909</wfw:commentRss>
      </item>
    
  <item>
    <title>Searching the Zend Framework's manual: Google Co-op to the rescue</title>
    <link>http://fashion.hosmoz.net/post/2007/07/19/Searching-the-Zend-Frameworks-manual%3A-Google-Co-op-to-the-rescue</link>
    <guid isPermaLink="false">urn:md5:a98cb0f821d1c34d0e78cb11080a6a43</guid>
    <pubDate>Thu, 19 Jul 2007 12:02:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>google</category><category>google co-op</category><category>manual</category><category>opensearch</category><category>php</category><category>zend framework</category>    
    <description>    &lt;p&gt;While the &lt;a href=&quot;http://framework.zend.com/manual/en/&quot;&gt;Zend Framework's manual&lt;/a&gt; is somewhat quite good, it lacks a feature that make it a really good manual: search. I find it very frustrating to not be able to make a simple search and therefor having to browse through the extensive &lt;acronym&gt;TOC&lt;/acronym&gt; to find what I'm actually looking for. Here enters the very handy &lt;a href=&quot;http://www.google.com/coop/&quot;&gt;Google co-op service&lt;/a&gt; which allows creation of custom search engines based on Google's indexes. It do not takes more than five minutes to setup a &lt;a href=&quot;http://www.google.com/coop/cse?cx=012533946567327475568%3An5g34x6bjjs&amp;amp;hl=en&quot;&gt;simple search engine&lt;/a&gt;, thus providing search capability to the manual :-)&lt;/p&gt;


&lt;p&gt;And as a good news never comes alone, I also made the &lt;a href=&quot;http://zend.riskle.com/opensearch/&quot;&gt;OpenSearch plugin&lt;/a&gt; for it.&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;I made a simpler url to remind of: &lt;a href=&quot;http://zend.riskle.com/search/&quot; title=&quot;http://zend.riskle.com/search/&quot;&gt;http://zend.riskle.com/search/&lt;/a&gt; and updated the opensearch thing to use that url.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/19/Searching-the-Zend-Frameworks-manual%3A-Google-Co-op-to-the-rescue#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/19/Searching-the-Zend-Frameworks-manual%3A-Google-Co-op-to-the-rescue#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/894</wfw:commentRss>
      </item>
    
  <item>
    <title>Pagination with the Zend Framework</title>
    <link>http://fashion.hosmoz.net/post/2007/07/15/Pagination-with-the-Zend-Framework</link>
    <guid isPermaLink="false">urn:md5:37f240d9a3578a1a954158eb14a63b40</guid>
    <pubDate>Sun, 15 Jul 2007 11:38:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>design pattern</category><category>pagination</category><category>php</category><category>proxy</category><category>view helper</category><category>zend framework</category><category>zend_db_table</category>    
    <description>    &lt;p&gt;Yesterday I came up with a small pagination component for the Zend Frameworks. It implements the &lt;a href=&quot;http://en.wikipedia.org/wiki/Proxy_pattern&quot;&gt;Proxy pattern&lt;/a&gt; around a &lt;code&gt;Zend_Db_Table&lt;/code&gt; object, and overloads the &lt;code&gt;fetchAll&lt;/code&gt; method. The main problem I encountered here was to retrieve the total number of rows for the table. I'm using a &lt;code&gt;Zend_Db_Select&lt;/code&gt; query for now, but I'll have to improve that. The component also features a view helper to draw the pagination links.&lt;/p&gt;


&lt;p&gt;You'll find the code for the &lt;a href=&quot;http://svn.riskle.com/library/Riskle/Db/Table/Paginate.php&quot;&gt;component&lt;/a&gt; and the &lt;a href=&quot;http://svn.riskle.com/library/Riskle/View/Helper/Paginate.php&quot;&gt;view helper&lt;/a&gt; on my &lt;acronym&gt;SVN&lt;/acronym&gt;.&lt;/p&gt;


&lt;p&gt;And here is how it is used in the controller:&lt;/p&gt;

&lt;pre&gt;
    public function indexAction() {
        $urls = new Riskle_Db_Table_Paginate(new Urls, $this-&amp;gt;_getParam('page'));
        $this-&amp;gt;view-&amp;gt;urlsList = $urls-&amp;gt;fetchAll(null, 'datetime DESC');
        $this-&amp;gt;view-&amp;gt;paginationInfos = $urls-&amp;gt;getPaginationInfos();
    }
&lt;/pre&gt;


&lt;p&gt;The view helper takes &lt;code&gt;paginationInfos&lt;/code&gt; as an argument:&lt;/p&gt;

&lt;pre&gt;
echo $this-&amp;gt;paginate($this-&amp;gt;paginationInfos);
&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;As pointed out by &lt;a href=&quot;http://totalement.geek.oupas.fr/&quot;&gt;Guy&lt;/a&gt;, the &lt;code&gt;_getPageCount&lt;/code&gt; method does not actually takes care of the &lt;code&gt;$where&lt;/code&gt; condition, thus rendering the class inefficient as getting the real totel number of items. This issue will be adressed in an upcoming version of the class :-)&lt;/p&gt;


&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;


&lt;p&gt;There's an &lt;a href=&quot;http://fashion.hosmoz.net/post/2007/07/31/Zend-Framework-Pagination-reloaded&quot;&gt;updated version of this component&lt;/a&gt; available.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/15/Pagination-with-the-Zend-Framework#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/15/Pagination-with-the-Zend-Framework#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/889</wfw:commentRss>
      </item>
    
  <item>
    <title>A Zend controller plugin to enable RESTful behaviour</title>
    <link>http://fashion.hosmoz.net/post/2007/07/14/A-Zend-controller-plugin-to-enable-REST-like-behaviour</link>
    <guid isPermaLink="false">urn:md5:a7322d8fa8be9d89dc76a2193831cfe0</guid>
    <pubDate>Sat, 14 Jul 2007 13:33:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>controller</category><category>mvc</category><category>php</category><category>plugin</category><category>REST</category><category>zend framework</category>    
    <description>&lt;p&gt;This is a simple controller plugin for the &lt;a href=&quot;http://framework.zend.com/&quot;&gt;Zend Framework&lt;/a&gt; which enable &lt;acronym&gt;REST&lt;/acronym&gt;ful behaviour. It basically adds the &lt;acronym&gt;HTTP&lt;/acronym&gt; method name to the action name, so that the &lt;acronym&gt;URL&lt;/acronym&gt; &lt;code&gt;http://example.com/foo/bar&lt;/code&gt; will be dispatched to &lt;code&gt;FooController::barGetAction&lt;/code&gt; on a GET, &lt;code&gt;FooController::barPostAction&lt;/code&gt; on a POST, etc.&lt;/p&gt;    &lt;p&gt;Here is the actual code:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;?php

class My_Controller_Plugin_Rest extends Zend_Controller_Plugin_Abstract {

        /**
         * Defines the format of the REST action name
         * Quite useless atm as the dispatcher will strip
         * any non alpha character
         */

        protected $_nameFormat = ':action:method';

        /**
         * Rewrites the action according to the http method
         */

        public function preDispatch() {
                $request = $this-&amp;gt;getRequest();
                $restActionName = $this-&amp;gt;_translateSpec($this-&amp;gt;_nameFormat, array(
                        'action' =&amp;gt; $request-&amp;gt;getActionName(),
                        'method' =&amp;gt; $request-&amp;gt;getMethod(),
                ));
                $request-&amp;gt;setActionName($restActionName);
        }

        /**
         * Inject values into a spec strings
         *
         * Allowed values are:
         *      :action =&amp;gt; the action name
         *      :method =&amp;gt; the http method
         *
         * @param string $spec
         * @param array $vars
         * @return string
         */

        protected function _translateSpec($spec, $vars = array()) {
                foreach($vars as $key =&amp;gt; $value) {
                        switch($key) {
                                case 'action':
                                case 'method':
                                        $$key = $value;
                                break;
                                default:
                                break;
                        }
                }

                $replacements = array(
                        ':action' =&amp;gt; $action,
                        ':method' =&amp;gt; $method,
                );

                $value = str_replace(array_keys($replacements), array_values($replacements),$spec);
                return $value;
        }
}
&lt;/pre&gt;


&lt;p&gt;Still, i'm not completly satisfied with this plugin. Plugins certainly allows for powerful control over what's going up in the dispatch process, but the dispatcher itself enforces a set of rules on actions naming (eg, you can't have a _ in it, it is stripped at dispatch time). Thus, I'm wondering on the pertinence of writting a custom dispatcher (read &lt;code&gt;My_Controller_Dispatcher_Rest&lt;/code&gt;) instead of just a plugin, which would enable far more possibilities.&lt;/p&gt;


&lt;p&gt;Btw, in case you're wondering, the plugins is used like this;&lt;/p&gt;

&lt;pre&gt;
$frontController = Zend_Controller_Front::getInstance();
$frontController-&amp;gt;registerPlugin(new My_Controller_Plugin_Rest);
&lt;/pre&gt;


&lt;p&gt;Easy heh ?&lt;/p&gt;


&lt;p&gt;Also, I'm not convinced that this plugin is &lt;em&gt;the way to go&lt;/em&gt; in matter of RESTful functionnality. I'm still wondering if it would not be better to have urls mapped to a single controller, replacing actions with &lt;em&gt;http methods&lt;/em&gt; (that is, &lt;code&gt;http://example.com/foo/bar&lt;/code&gt; would map to &lt;code&gt;FooController::getAction&lt;/code&gt;, etc).&lt;/p&gt;


&lt;p&gt;Any opinions around ?&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/14/A-Zend-controller-plugin-to-enable-REST-like-behaviour#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/14/A-Zend-controller-plugin-to-enable-REST-like-behaviour#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/887</wfw:commentRss>
      </item>
    
</channel>
</rss>