Lately I’ve been experimenting with KnockoutJS, a JavaScript framework for streamlining client-side data and UI updates. I’ve found it wonderfully easy to implement Knockout’s out-of-box functionality and obsolete tons of my custom code. This conversion was helped by Knockout’s thorough documentation and numerous working examples. But I soon had the desire to integrate Knockout with Quicksand, a jQuery plugin for animating list sorts and filters. This quickly proved difficult, probably because I’m still new to Knockout, but with help from the Knockout forums I eventually created a custom binding to apply Quicksand animations to a Knockout
observableArray. No one else has published such a binding so I’m sharing mine for others’ benefit. But beware that it may not handle every circumstance you throw at it.
Continue reading
Category Archives: Tech
Relative paths in PHP INI
I’ve always preferred to use relative file paths in my PHP INI, but ran into problems when running PHP from different directories. For example, a directive like
error_log = "../logs/php_errors.log" will resolve to different paths when invoked by
/public/index.php (e.g. Zend Framework) and
/cli-config.php (e.g. Doctrine CLI). Some INI directives can be set at runtime by our application (see PHP_INI_ALL), but many cannot. I finally found the solution with environment variables.
Continue reading
Microsoft Office Link Pre-fetching and Single Sign-On
I updated a site to use Single Sign-On (SSO) capability, specifically with Shibboleth, and was shocked to discover that links to the site in Microsoft Office files stopped working. This turns out to be a known issue with no definitive solution. So after thorough troubleshooting I created my own workaround, and as usual I hope sharing it will benefit others.
Continue reading
Multiple forms on the same page in Zend Framework
Processing two forms on the same page is not the simplest task in the Zend Framework. About a year ago I encountered this problem and studied others’ approaches. Eventually I hacked together a solution with multiple actions and lots of redundant code. But I was recently making updates to this page and found a more elegant method for handling multiple forms.
Continue reading
Autoloading Symfony using Doctrine with Zend Framework
On some projects I use the Doctrine Object Relational Mapper, a fantastic library for modeling database objects. To combine it with Zend Framework 1, I use Guilherme Blanco’s Bisna application resource. I recently upgraded a project to the latest version of Doctrine and suddenly couldn’t autoload the Symphony classes. It took far too long for me to figure out the problem, so I hope I can spare someone else the same trouble.
Continue reading
Don’t host on a .255 IP address
Most of the websites that I build at work are for internal use, but last year I created a site with a public audience. Everything was going well post-launch until I received a handful of reports from users who couldn’t access the site. They tried clearing cookies, switching browsers, switching computers, and resetting modems, but nothing worked. Visiting any page on the site would result in an error like “Internet Explorer cannot display the webpage” or “Unable to connect”. They could view other sites hosted on my network, but nothing hosted on the same server as this public site. The PHP and server logs recorded nothing unusual. What was happening?
Continue reading
Preserve encoded slashes in URL
To use a reserved character in a URL without invoking its special meaning, the character must be URL encoded. For example, a ? separates the page name from the query string, a & separates query string parameters, and a = separates parameter names from their values. These characters must be converted to %3F, %26, and %3D respectively if we want them interpreted literally.
In MVC applications, these special characters are less common because URLs follow a pattern like
/Module/Controller/Action/Parameter1/Parameter2. In this case, the most important reserved character is the forward slash. Let’s see how to handle slashes in Zend Framework 1 URLs.
Continue reading
MVC Form Layer
Forms are a tricky part of any Model-View-Controller (MVC) application. They incorporate validation, presentation, and security logic that spans all tiers of the application. Separating these concerns is difficult but important. I’ll walk through how I use
Zend_Form in Zend Framework 1, but the same principles should apply to any MVC application.
Continue reading
Using sprintf with multiple iterations
PHP’s built-in
sprintf() function is great for formatting complicated output and improving code readability. I recently had the need to output a string multiple times with some changes each time. Here’s how I did it.
Continue reading
Zend_Form_Decorator_Fieldset for individual elements
If you want to include a
<fieldset> in your
Zend_Form, you might try the
Zend_Form_Decorator_Fieldset decorator. But it’s not apparent that this decorator is meant for the form and not the individual elements in it. Instead, here’s a custom decorator to render your
Zend_Form_Element with a
<fieldset>.
Continue reading