June 6th, 2010 by Eric
As PHP applications grow into complex object-oriented systems, developers look to create centralized components to execute repetitive tasks. These include logging, emailing, redirects, and more. The Observer pattern is a commonly used design pattern to hook such components into an application during runtime, thereby making them reusable. Since PHP 5.1, there are two interfaces built into the Standard PHP Library (SPL) that can be implemented to use the Observer pattern in your application. They are SplSubject, and SplObserver.
Continue reading ‘Implementing the Observer Pattern with SplObserver and SplSubject’
May 17th, 2010 by Eric
As web developers we are familiar with the DRY (Don’t Repeat Yourself) principle of programming. Cut & paste is the bane of object-oriented programmers, and we will frequently hear the phrase “Don’t reinvent the wheel”. However, I typically find myself and other colleagues in the world of PHP doing just that. The plethora of actively developed PHP Frameworks are a fluid testament to this fact. So are other libraries – sajax/xajax/projax for PHP Ajax work, jQuery/Dojo/Prototype/Mootools for JavaScript, and the list goes on.
Sure, there are unique qualities and features that separate third-party libraries, but the principle overlap is what – 75%? 80%? So why do we do it? The answer may be pride. Or, as someone so excellently put it this past weekend, our answer to “Don’t reinvent the wheel” becomes “Our wheels are rounder”. Continue reading ‘Our Wheels Are Rounder’
October 18th, 2009 by Eric
Have you ever wanted to set up an application that displays tabular data, and wanted to use the same view for each query? While PHP is excellent for writing small-footprint queries, its ability to be embedded in HTML leaves the creativity to the programmer to figure out a consistent display solution for tabular data.
We need two things – first, we need a way to dynamically retrieve table information, query information, and query results. Second, we need a way to dynamically build the display based on the information we have. Using the metadata methods of PDO, along with PEAR::HTML_Table_Matrix, we can do just this. Continue reading ‘Flexible Data Display with PDO and HTML_Table_Matrix’
September 15th, 2009 by Eric
Today I encountered a problem that many developers will likely face while building a web application with Ajax, so I wanted to share my experience with it.
The Problem:
You create a web site with the goal of consuming content from the web. This may be in the form of a geocoding service, or perhaps a lightbox service for browsing images. You need to load an external resource though Ajax. The XMLHttpRequest object cannot make a connection, and you receive a javascript error, or a blank page. Continue reading ‘Writing a Cross-Domain Proxy in PHP’
July 10th, 2009 by Eric
I wanted to write a quick post about a library one of my co-workers stumbled upon this week. It is called php.js and is a compilation of php functions ported to javascript. That sounds pretty convenient!
Continue reading ‘PHP and Javascript Combine with PHP.JS’
May 29th, 2009 by Eric
Tonight I started working on a set of classes that will build forms for Propel objects. While Propel already has implementations of PatForms and HTML_QuickForm, they are both not up-to-date in svn. They both also require Creole for gathering metadata, and I am not at all interested in integrating another library into this project – especially one labeled “dead” on its own site.
Continue reading ‘Working on a Propel Form Builder…’
May 26th, 2009 by Eric
Recently when browsing past issues of php|architect magazine, I came across mention of a Firefox add-on called FirePHP. For those who have not heard of it, FirePHP is both a Firefox add-on and a PHP library used to send messages to the Firebug console.
Continue reading ‘Quick PHP Debugging with FirePHP’