<?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 - php</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>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>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>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>Quick php5 pre-migration check</title>
    <link>http://fashion.hosmoz.net/post/2007/08/30/Quick-php5-pre-migration-check</link>
    <guid isPermaLink="false">urn:md5:2e44d92a67a44664619078b9766c1b5f</guid>
    <pubDate>Thu, 30 Aug 2007 11:57:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Geekeries</category>
        <category>migration</category><category>php</category><category>php5</category><category>quick</category><category>syntax check</category><category>tips</category>    
    <description>    &lt;p&gt;If you're wondering how much of a hassle it would be to migrate your app / codebase to php5, try the following command line (after having installed the php5-cli package of course):&lt;/p&gt;


&lt;pre&gt;find . -name &amp;quot;*.php&amp;quot; -exec /usr/bin/php5 -l {} \; | grep -v 'No syntax errors'&lt;/pre&gt;


&lt;p&gt;It'll show you all the files with syntax errors in it.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/08/30/Quick-php5-pre-migration-check#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/08/30/Quick-php5-pre-migration-check#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/1006</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>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>
    
  <item>
    <title>Get the current $view from a view helper</title>
    <link>http://fashion.hosmoz.net/post/2007/07/01/Get-the-current-view-from-a-view-helper</link>
    <guid isPermaLink="false">urn:md5:6ea0301d94edd4aa84034fb7e5596e87</guid>
    <pubDate>Sun, 01 Jul 2007 22:24:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>php</category><category>tips</category><category>view</category><category>view helper</category><category>zend framework</category>    
    <description>    &lt;p&gt;So you're making your own view helper and you need, for a reason, to access the running &lt;code&gt;$view&lt;/code&gt; instance. Don't worry, all you have to do is implement a &lt;code&gt;setView()&lt;/code&gt; method which will be called on your helper's instantiation, with the &lt;code&gt;$view&lt;/code&gt; as argument:&lt;/p&gt;

&lt;pre&gt;
class My_View_Helper_SpecialPurpose {
	
	protected $_view = null;
	
	public function setView($view) {
		$this-&amp;gt;_view = $view;
	}

}
&lt;/pre&gt;


&lt;p&gt;And voila !&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/07/01/Get-the-current-view-from-a-view-helper#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/07/01/Get-the-current-view-from-a-view-helper#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/873</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.0.0 RC3</title>
    <link>http://fashion.hosmoz.net/post/2007/06/25/Zend-Framework-100-RC3</link>
    <guid isPermaLink="false">urn:md5:517ea6955804c485d7b4dbefeffa105f</guid>
    <pubDate>Mon, 25 Jun 2007 15:57:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>irc</category><category>pear</category><category>php</category><category>zend framework</category><category>zftalk</category>    
    <description>    &lt;p&gt;Allez hop, la RC3 du Zend Framework est sortie (il y a 2 jours).&lt;/p&gt;


&lt;p&gt;J'en profite pour faire un peu de pub pour &lt;a href=&quot;http://www.zftalk.com/&quot;&gt;zftalk&lt;/a&gt;, un chan &lt;acronym&gt;IRC&lt;/acronym&gt; sympa.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/06/25/Zend-Framework-100-RC3#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/06/25/Zend-Framework-100-RC3#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/864</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 1.0.0 RC2</title>
    <link>http://fashion.hosmoz.net/post/2007/06/13/Zend-Framework-100-RC2</link>
    <guid isPermaLink="false">urn:md5:b299442c6e99bae7d279ef4e27c191f8</guid>
    <pubDate>Wed, 13 Jun 2007 16:17:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>pear</category><category>php</category><category>zend framework</category>    
    <description>    &lt;p&gt;Au fait, j'ai mis en ligne le package pear de la 1.0 RC2 du Zend Framework hier, avec un peu de retard donc, puisque j'étais occupé à imiter les oiseaux :)&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/06/13/Zend-Framework-100-RC2#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/06/13/Zend-Framework-100-RC2#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/842</wfw:commentRss>
      </item>
    
  <item>
    <title>Zend Framework 0.9.3</title>
    <link>http://fashion.hosmoz.net/post/2007/05/07/Zend-Framework-093</link>
    <guid isPermaLink="false">urn:md5:7aac95ba8ef7949d323f17fe78199868</guid>
    <pubDate>Mon, 07 May 2007 09:08:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>pear</category><category>php</category><category>phpmafia</category><category>zend framework</category>    
    <description>    &lt;p&gt;Dernière ligne droite avant les premières 1.0 RC, &lt;a href=&quot;http://devzone.zend.com/node/view/id/2002&quot;&gt;la beta 0.9.3 du Zend Framework est sortie&lt;/a&gt;, et son package est disponible sur &lt;a href=&quot;http://pear.phpmafia.net/&quot;&gt;le channel PEAR PHPMafia&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/05/07/Zend-Framework-093#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/05/07/Zend-Framework-093#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/788</wfw:commentRss>
      </item>
    
  <item>
    <title>Débuter avec le Zend Framework</title>
    <link>http://fashion.hosmoz.net/post/2007/04/12/Debuter-avec-le-Zend-Framework</link>
    <guid isPermaLink="false">urn:md5:e1875eb76e5eb90ebb656be4b001833a</guid>
    <pubDate>Thu, 12 Apr 2007 00:31:00 +0200</pubDate>
    <dc:creator>Geoffrey</dc:creator>
        <category>Coding</category>
        <category>doc</category><category>howto</category><category>php</category><category>traduction</category><category>tutorial</category><category>zend framework</category>    
    <description>    &lt;p&gt;&lt;a href=&quot;http://akrabat.com/2007/04/11/premiers-pas-avec-le-zend-framework/&quot;&gt;Pour&lt;/a&gt; &lt;a href=&quot;http://g-rossolini.developpez.com/tutoriels/php/zend-framework/debuter/?page=sommaire&quot;&gt;info&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;Je suis un peu triste parce que je voulais m'atteler à cette tâche, mais bon il faut croire que j'ai trop lambiné :)&lt;/p&gt;</description>
    
    
    
          <comments>http://fashion.hosmoz.net/post/2007/04/12/Debuter-avec-le-Zend-Framework#comment-form</comments>
      <wfw:comment>http://fashion.hosmoz.net/post/2007/04/12/Debuter-avec-le-Zend-Framework#comment-form</wfw:comment>
      <wfw:commentRss>http://fashion.hosmoz.net/feed/rss2/comments/756</wfw:commentRss>
      </item>
    
</channel>
</rss>