<?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 - Coding</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>About the self keyword in static methods</title>
    <link>http://fashion.hosmoz.net/post/2008/07/14/About-the-self-keyword-in-static-methods</link>
    <guid isPermaLink="false">urn:md5:610999c6e714c4d650b1d2ea45ffc0b3</guid>
    <pubDate>Mon, 14 Jul 2008 16:04:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>callback</category><category>nonsense</category><category>php</category><category>self</category><category>static</category><category>weird</category>    
    <description>    &lt;p&gt;While setting up a test server for some software I wrote at the office, I eventually noticed the following notice:&lt;/p&gt;

&lt;pre&gt;
Notice: Use of undefined constant self - assumed 'self'
&lt;/pre&gt;


&lt;p&gt;That surprised me, because 1) I though self were some kind of &amp;quot;superglobal&amp;quot; constant or a special token of the parser, always automatically available in a static method and 2) the code works. So what's up in there ? Let's make a simple test:&lt;/p&gt;

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

class foo {
	static public function bar() {
		var_dump(is_callable(array('self', 'foobar')));
		var_dump(is_callable(array(self, 'foobar')));

		var_dump(class_exists('self'));
		var_dump(class_exists(self));

		self::foobar();
	}

	static public function foobar() {
	}
}

foo::bar();

&lt;/pre&gt;


&lt;p&gt;Executing the above code will yeld the following result:&lt;/p&gt;

&lt;pre&gt;
bool(true)

Notice: Use of undefined constant self - assumed 'self' in /home/geoffreyb/test.php on line 6
bool(true)
bool(false)

Notice: Use of undefined constant self - assumed 'self' in /home/geoffreyb/test.php on line 9
bool(false)
&lt;/pre&gt;


&lt;p&gt;What do we learn here ? Not much actually. It seems like &lt;code&gt;self&lt;/code&gt; as a constant is only available when used with the scope resolution operator, aka double-colon or paamayim nekudotayim. When you want to use it in, for example, a callback definition, use a string representation of self:&lt;/p&gt;

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

is_callable(array('self', 'bar'));
call_user_func(array('self', 'bar'));
&lt;/pre&gt;


&lt;p&gt;Which, while making absolutely no sense at all, works. Another way to get around this is to use the &lt;code&gt;get_class()&lt;/code&gt; function that, without any argument, will return the name of the class you're currently in (&lt;code&gt;foo&lt;/code&gt; in my example).&lt;/p&gt;


&lt;p&gt;After a bit more investiging, I found out that there is nothing special about the &lt;em&gt;self&lt;/em&gt; token, which is actually a string token. You can check this very easily with the following code:&lt;/p&gt;

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

class foo {
	static public function bar() {
		self::foobar();
	}
}

var_dump(token_get_all(file_get_contents(__FILE__)));
&lt;/pre&gt;


&lt;p&gt;Somewhere inside the output, you'll find the following piece of text:&lt;/p&gt;

&lt;pre&gt;
  array(2) {
    [0]=&amp;gt;
    int(307)
    [1]=&amp;gt;
    string(4) &amp;quot;self&amp;quot;
  }
&lt;/pre&gt;


&lt;p&gt;And the token id &lt;code&gt;307&lt;/code&gt; is resolved by &lt;code&gt;token_name&lt;/code&gt; to &lt;code&gt;string&lt;/code&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/07/14/About-the-self-keyword-in-static-methods#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/07/14/About-the-self-keyword-in-static-methods#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1112</wfw:commentRss>
      </item>
    
  <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>ruby: url_to_constant</title>
    <link>http://fashion.hosmoz.net/post/2008/03/27/ruby%3A-url_to_constant</link>
    <guid isPermaLink="false">urn:md5:5bc21c2e576e73435e4b1e0c555fffe1</guid>
    <pubDate>Thu, 27 Mar 2008 23:04:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>constant</category><category>ruby</category><category>url</category><category>useless</category>    
    <description>    &lt;p&gt;A small bit of ruby to get a constant from an &lt;acronym&gt;URL&lt;/acronym&gt;:&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;require&lt;/span&gt; 'uri'&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; url_to_constant&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;url&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#0000FF; font-weight:bold;&quot;&gt;return&lt;/span&gt; URI.&lt;span style=&quot;color:#9900CC;&quot;&gt;parse&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;url&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color:#9900CC;&quot;&gt;host&lt;/span&gt;.&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;gsub&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;/^www\./, ''&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color:#9900CC;&quot;&gt;capitalize&lt;/span&gt;.&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;gsub&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;/&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#91;&lt;/span&gt;^a-z&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#91;&lt;/span&gt;a-z&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#93;&lt;/span&gt;/i&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#123;&lt;/span&gt; |m| m.&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;gsub&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;/&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#91;&lt;/span&gt;^a-z&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#93;&lt;/span&gt;/, ''&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color:#9900CC;&quot;&gt;upcase&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#125;&lt;/span&gt;.&lt;span style=&quot;color:#9900CC;&quot;&gt;constantize&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;Nothing exceptionnal here, just a pretext to post something.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2008/03/27/ruby%3A-url_to_constant#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/03/27/ruby%3A-url_to_constant#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1091</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>Plugin &quot;related by tags&quot; pour dotclear 2, deuxième</title>
    <link>http://fashion.hosmoz.net/post/2008/03/10/Plugin-related-by-tags-pour-dotclear-2-deuxieme</link>
    <guid isPermaLink="false">urn:md5:5e7f17894657fe0198135403c49f72f8</guid>
    <pubDate>Mon, 10 Mar 2008 21:48:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>dotclear2</category><category>plugin</category><category>related by tags</category>    
    <description>    &lt;p&gt;Après de longs mois d'attente, le &lt;em&gt;related by tags&lt;/em&gt; nouveau arrive enfin ! Au menu des réjouissances, une interface de configuration, ainsi qu'un widget font leur apparition. Vous disposez donc désormais de deux manières d'afficher les billets liés, directement en modifiant le template comme avant:&lt;/p&gt;

&lt;pre&gt;
{{tpl:include src=&amp;quot;_related_by_tags.html&amp;quot;}}
&lt;/pre&gt;


&lt;p&gt;ou tout simplement en activant le widget correspondant, que vous pouvez configurer comme vous l'entendez. Bien sur, ce widget ne s'affichera que lors de la visualisation d'un billet.&lt;/p&gt;


&lt;p&gt;Au chapitre des fonctionnalités / bugfix manquant(e)s, on notera le bug lié à l'utilisation de postgresql, ainsi que la traduction française, qui sera pour plus tard.&lt;/p&gt;


&lt;p&gt;Encore une fois, n'hésitez pas à poster tous vos commentaires ici même.&lt;/p&gt;</description>
    
          <enclosure url="http://fashion.hosmoz.net/public/plugin-related_by_tags-2.pkg.gz"
      length="5384" type="application/x-gzip" />
          <enclosure url="http://fashion.hosmoz.net/public/plugin-related_by_tags-2.tar.gz"
      length="3568" type="application/x-gzip" />
    
    
          <comments>http://fashion.hosmoz.net/post/2008/03/10/Plugin-related-by-tags-pour-dotclear-2-deuxieme#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2008/03/10/Plugin-related-by-tags-pour-dotclear-2-deuxieme#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1087</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>yaml, activerecord and acts_as_nested_set</title>
    <link>http://fashion.hosmoz.net/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set</link>
    <guid isPermaLink="false">urn:md5:8723be74d366c359a8c02a308d5844be</guid>
    <pubDate>Sun, 02 Dec 2007 16:41:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>activerecord</category><category>rails</category><category>rake</category><category>ruby</category><category>yaml</category>    
    <description>    &lt;p&gt;I used to use this &lt;a href=&quot;http://thecaribbeanweblog.com/index.php/2007/06/21/150-yaml-et-activerecord-et-sql-plus-generalement&quot;&gt;yaml_to_ar lib&lt;/a&gt; from &lt;a href=&quot;http://thecaribbeanweblog.com/&quot;&gt;christophe&lt;/a&gt; to load categories tree into my database, using &lt;code&gt;&lt;a href=&quot;http://wiki.rubyonrails.org/rails/pages/ActsAsTree&quot;&gt;acts_as_tree&lt;/a&gt;&lt;/code&gt; in the model that was perfect. Arrived the time when I felt the need to use &lt;code&gt;&lt;a href=&quot;http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html&quot;&gt;acts_as_nested_set&lt;/a&gt;&lt;/code&gt; instead, for which I had to fill the &lt;code&gt;lft&lt;/code&gt; and &lt;code&gt;rgt&lt;/code&gt; columns. So I just rewrote the &lt;em&gt;yaml_to_ar&lt;/em&gt; piece of code (put this in &lt;code&gt;lib/yaml_to_ar.rb&lt;/code&gt;):&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;require&lt;/span&gt; 'yaml'&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;class&lt;/span&gt; YAML_to_AR&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; initialize&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;file, model&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @data = File.&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;open&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;file&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#123;&lt;/span&gt; |yf| YAML::&lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;load&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt; yf &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; @model = model&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;data = @data, parent = &lt;span style=&quot;color:#0000FF; font-weight:bold;&quot;&gt;nil&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;if&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;Array&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt; |val|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;val, parent&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;elsif&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? Hash&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;each&lt;/span&gt; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt; |key,val|&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parent = @model.&lt;span style=&quot;color:#9900CC;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;:title =&amp;gt; key&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; process&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;val, parent&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;elsif&lt;/span&gt; data.&lt;span style=&quot;color:#9900CC;&quot;&gt;is_a&lt;/span&gt;? &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;String&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; parent.&lt;span style=&quot;color:#9900CC;&quot;&gt;add_child&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;@model.&lt;span style=&quot;color:#9900CC;&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;:title =&amp;gt; data&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;This should handle both &lt;code&gt;acts_as_tree&lt;/code&gt; and &lt;code&gt;acts_as_nested&lt;/code&gt;. To ease things a bit further, I also wrote a rake task (to drop in &lt;code&gt;lib/tasks/db_load_categories.rake&lt;/code&gt; for example):&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;namespace :db &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; desc &lt;span style=&quot;color:#996600;&quot;&gt;&amp;quot;Loads categories defaults data&amp;quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; task :load_categories =&amp;gt; :environment &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#CC0066; font-weight:bold;&quot;&gt;require&lt;/span&gt; 'lib/yaml_to_ar'&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Category.&lt;span style=&quot;color:#9900CC;&quot;&gt;delete_all&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; categories = YAML_to_AR.&lt;span style=&quot;color:#9900CC;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;'db/categories.&lt;span style=&quot;color:#9900CC;&quot;&gt;yml&lt;/span&gt;', Category&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; categories.&lt;span style=&quot;color:#9900CC;&quot;&gt;process&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;Now I just &lt;code&gt;rake db:load_categories&lt;/code&gt;, and voila !&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/12/02/yaml-activerecord-and-acts_as_nested_set#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1077</wfw:commentRss>
      </item>
    
  <item>
    <title>my first rails plugin: named_resources</title>
    <link>http://fashion.hosmoz.net/post/2007/11/28/my-first-rails-plugin%3A-named_resources</link>
    <guid isPermaLink="false">urn:md5:28c1356e1cfe998c3393fe046bb94dcb</guid>
    <pubDate>Wed, 28 Nov 2007 13:00:00 +0100</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>plugin</category><category>rails</category><category>resources</category><category>ruby</category>    
    <description>    &lt;p&gt;It's a simple plugin (2 lines of code beside class and modules declarations) which allows routes created via the &lt;code&gt;map.resources&lt;/code&gt; mechanism to be customized. Say you have the following map:&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;map.&lt;span style=&quot;color:#9900CC;&quot;&gt;resources&lt;/span&gt; :members&lt;/code&gt;


&lt;p&gt;It will generate routes like:&lt;/p&gt;

&lt;pre&gt;
/members
/members/:id
/members/new
&lt;/pre&gt;


&lt;p&gt;No say you want to i18n your app, in french for example, what do you do ? You just can't out of the box. This is where my plugin enters into action, just add a &lt;code&gt;:route_name&lt;/code&gt; parameter to the &lt;code&gt;map.resources&lt;/code&gt; call and you're set:&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;map.&lt;span style=&quot;color:#9900CC;&quot;&gt;resources&lt;/span&gt; :members, :route_name =&amp;gt; 'utilisateurs'&lt;/code&gt;


&lt;p&gt;will generate routes like:&lt;/p&gt;
&lt;pre&gt;
/utilisateurs
/utilisateurs/:id
/utilisateurs/new
&lt;/pre&gt;


&lt;p&gt;It shall also work for nested resources, although I did not test that.&lt;/p&gt;


&lt;p&gt;The code is actually pretty simple:&lt;/p&gt;

&lt;code class=&quot;ruby&quot;&gt;&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;module&lt;/span&gt; ActionController&lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;module&lt;/span&gt; Resources&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;class&lt;/span&gt; Resource&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;def&lt;/span&gt; path&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; route_name = @options.&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;include&lt;/span&gt;?&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#40;&lt;/span&gt;:route_name&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#41;&lt;/span&gt; ? @options&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#91;&lt;/span&gt;:route_name&lt;span style=&quot;color:#006600; font-weight:bold;&quot;&gt;&amp;#93;&lt;/span&gt; : @plural&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @path ||= &lt;span style=&quot;color:#996600;&quot;&gt;&amp;quot;#{path_prefix}/#{route_name}&amp;quot;&lt;/span&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt; &lt;br /&gt;
&amp;nbsp; &lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt; &lt;br /&gt;
&lt;span style=&quot;color:#9966CC; font-weight:bold;&quot;&gt;end&lt;/span&gt;&lt;/code&gt;


&lt;p&gt;To install just use &lt;code&gt;script/plugin&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;
script/plugin install http://tools.assembla.com/svn/riskle/rails/plugins/named_resources
&lt;/pre&gt;


&lt;p&gt;or to install as an svn:external resource:&lt;/p&gt;

&lt;pre&gt;
script/plugin install -x http://tools.assembla.com/svn/riskle/rails/plugins/named_resources
&lt;/pre&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/11/28/my-first-rails-plugin%3A-named_resources#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/11/28/my-first-rails-plugin%3A-named_resources#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1076</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>Plugin &quot;related by tags&quot; pour dotclear 2</title>
    <link>http://fashion.hosmoz.net/post/2007/10/04/plugin-related-by-tags-pour-dotclear-2</link>
    <guid isPermaLink="false">urn:md5:0512ecee686bfffdfce5d2a547b4b1dc</guid>
    <pubDate>Thu, 04 Oct 2007 20:50:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>dotclear2</category><category>plugin</category><category>related by tags</category>    
    <description>    &lt;p&gt;&lt;strong&gt;update&lt;/strong&gt;: &lt;a href=&quot;http://fashion.hosmoz.net/post/2008/03/10/Plugin-related-by-tags-pour-dotclear-2-deuxieme&quot;&gt;nouvelle version disponible&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Allez hop, j'ai codouillé rapidement aujourd'hui un plugin dotclear 2 pour afficher une liste des billets ayant le ou les mêmes tags que le billet en cours de lecture par l'internaute. Il est téléchargeable dès maintenant sous forme &lt;a href=&quot;http://fashion.hosmoz.net/public/plugin-related_by_tags-1.tar.gz&quot;&gt;d'archive tar gzipée&lt;/a&gt; ou directement de &lt;a href=&quot;http://fashion.hosmoz.net/public/plugin-related_by_tags-1.pkg.gz&quot;&gt;package dotclear&lt;/a&gt;. Pour l'utiliser, rien de plus simple, il suffit d'ajouter le tag suivant dans votre template, à l'endroit où vous souhaitez afficher la liste des billets:&lt;/p&gt;

&lt;pre&gt;
{{tpl:include src=&amp;quot;_related_by_tags.html&amp;quot;}}
&lt;/pre&gt;


&lt;p&gt;Et voilà c'est tout :-)&lt;/p&gt;


&lt;p&gt;Bon par contre, il faut faire gaffe a comment on tag ses billets (genre pour celui là j'ai preferré ne pas le taguer &lt;em&gt;php&lt;/em&gt; histoire d'avoir des résultats plus pertinents).&lt;/p&gt;


&lt;p&gt;ps: si quelqu'un connait un moyen d'éviter d'avoir a rajouter un bout de code au template je suis preneur (mais j'ai la flemme de chercher là tout de suite).&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/10/04/plugin-related-by-tags-pour-dotclear-2#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/10/04/plugin-related-by-tags-pour-dotclear-2#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1058</wfw:commentRss>
      </item>
    
  <item>
    <title>PDO not throwing an exception when it should</title>
    <link>http://fashion.hosmoz.net/post/2007/10/01/PDO-not-throwing-an-exception-when-it-should</link>
    <guid isPermaLink="false">urn:md5:60df19dc3606fa5537a420e0bd129709</guid>
    <pubDate>Mon, 01 Oct 2007 17:40:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>bug</category><category>exceptions</category><category>mysql</category><category>pdo</category><category>php</category>    
    <description>    &lt;p&gt;Today I ran into an issue that I already ran into a few weeks ago when I did not have time to dig up, but today I had this time (this plus it's a really annoying issue as you'll see). The main symptom is that PDO does not throws exceptions when you'd expect it to. It's very annoying. The reason, in my case, seems to be that I am querying an old mysql (3.23.x in my case but any 4.x will do &lt;a href=&quot;http://bugs.php.net/bug.php?id=42371&quot;&gt;according to this bug report&lt;/a&gt;). I was not able to find any info from google, so I'm posting this here so that people know :-)&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/10/01/PDO-not-throwing-an-exception-when-it-should#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/10/01/PDO-not-throwing-an-exception-when-it-should#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1054</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>
    
</channel>
</rss>