<feed xmlns="http://www.w3.org/2005/Atom">
  <div xmlns="http://www.w3.org/1999/xhtml" class="info">
         This is an Atom formatted XML site feed.
         It is intended to be viewed in a Newsreader or syndicated to another site.
         Please visit <a href="http://www.atomenabled.org/">atomenabled.org</a> for more info.
  </div>
  <title>Blogging Pubbitch</title>
  <link href="http://www.pubbitch.org/blog/index.atom" rel="self"/>
  <link href="http://www.pubbitch.org/blog/index.html" rel="alternate" type="text/html"/>
  <id>http://www.pubbitch.org/blog/tech/php.atom</id>
  <updated>2008-07-25T21:13:24+00:00</updated>
  <author>
    <name>Simon Stewart</name>
  </author>
  <entry>
    <id>tag:pubbitch.org,entry,2004:153</id>
    <title>Front Controller vs. Page Controller</title>
    <link href="http://www.pubbitch.org/blog/2004/03/29/front_controller_vs_page_controller" rel="alternate"/>
    <updated>2005-12-14T13:15:21Z</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>The other day I set out to put together a Front Controller in PHP. The good news: it was stupidly easy to do. The bad news: it didn't feel "PHP-ish" at all. This is probably because a front controller needs a certain amount of supporting baggage, such as some way to configure it. A page controller suffers far less from this problem.
</p><p>
Taking a step back, why would a front controller be used? The pithy answer is that it allows the developer to reuse chunks of code as simply as possible. In Java, there's an architectural impetus to avoid using page controllers, since that generally means putting more logic than necessary into, say, a JSP page. But there's no such pressure in PHP because of the nature of the language.
</p><p>
The "PHP-ish" way of doing things involves putting the common logic in include files, and then referecing them as needed before churing out the page. In order to establish a strong separation of view from controller, it might be adventageous to use something like <a href="http://smarty.php.net/">Smarty</a> for the view, but there's no reason not to use PHP all the way through (indeed, Smarty "compiles down" to PHP)
</p><p>
So, it looks like I was wrong when I said that I might well end up <a href="/blog4php/blog.php?entry=2004/03/24/next_series_of_articles">plumping for a front controller</a>. It's a bad fit for the language, and it gets in the way of getting things done. Maybe next time. ;)</p>      </div>
    </content>
  </entry>
  <entry>
    <id>tag:pubbitch.org,entry,2004:154</id>
    <title>Next Series of Articles</title>
    <link href="http://www.pubbitch.org/blog/2004/03/24/next_series_of_articles" rel="alternate"/>
    <updated>2005-12-14T13:15:21Z</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>I've started putting together the code that will form the basis for my next set of articles for <a href="http://www.netmag.co.uk/">.Net magazine</a>. The articles will focus on exploring the <abbr title="Model View Controller">MVC</abbr> pattern and will ultimately lead to the creation of a calendar application (because the world needs more of these)
</p><p>
One of the early design choices is to decide how the controller will be implemented. Coming from a Java background, it would natural to try and apply the pattern I've seen in <a href="http://www.opensymphony.com/webwork">WebWork</a> and the J2EE spec, where certain URLs are handled by a central dispatcher which delegates to specific actions, the results of which are forwarded to the expected view (the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/DesFrontController.asp">Front Controller</a> pattern) However, PHP applications are normally coded with a series of individual pages interacting with the model (the <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/DesPageController.asp">Page Controller</a> pattern)
</p><p>
For the sake of providing a clearer demonstration of how a controller works, I might well end up plumping for a basic front controller based framework. Things are made slightly easier by Apache's <a href="http://httpd.apache.org/docs-2.0/content-negotiation.html">content negotiation</a> facilities (especially MultiViews) which provide a simple mechanism to route non-existant file requests to a central handler. For the sake of completeness, I should also probably add a handler for when MultiViews aren't available or activated (such as when the user insists on using IIS)
</p><p>
This should be interesting. For me, at least. I'll try and develop it using a <abbr title="Test Driven Development">TDD</abbr> approach and see how far I get today.</p>      </div>
    </content>
  </entry>
  <entry>
    <id>tag:pubbitch.org,entry,2003:155</id>
    <title>PEAR</title>
    <link href="http://www.pubbitch.org/blog/2003/05/27/pear" rel="alternate"/>
    <updated>2005-12-14T13:15:21Z</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Note to self: when hacking PHP, always check the <a href="http://pear.php.net/">PEAR</a> first. Just spent a constructive half hour rooting through it and found a cornucopia of handy bits and pieces, including classes for handling config files (yay!), caching and XML-RPC (which appears to be a rewrite of <a href="http://phpxmlrpc.sourceforge.net">this</a> to PEAR standards)
</p><p>
This could have saved an enormous amount of time. Oh well. *shrugs*</p>      </div>
    </content>
  </entry>
</feed>
 
