Dynamically retrofitting legacy JavaScript classes as Backbone models

The code.

When I originally wrote my Jeopardy Scorekeeper single-page app with just JavaScript and jQuery, I wrote what are essentially model classes that implement the game and player logic (keeping score, tracking remaining clues, rotating players, etc.) and that have no user interface functionality, other than the abstract concept of the Jeopardy UI (the board, etc.). I decided to try refactoring the Jeopardy Scorekeeper with Backbone, but I also wanted to:

Continue reading

Kohana 3.2 ORM-based user auth error: “ORM_Validation_Exception [ 0 ]: Failed to validate array”

After being interested in it for a while, I’ve started experimenting with Kohana (v 3.2). When I started working with the ORM-based user authentication it ships with, I immediately ran into some trouble. Searches turned up scant information, so I’m posting this to help people who run into the same problem.

Continue reading

Wanted: PHP built-in functionality for dynamically accessing array elements at arbitrary nesting depth

In general I’ve been pretty happy with the array implementation in PHP, finding them pretty versatile, flexible, and easy to use. I like that you can just mix integer and string keys, associative arrays are ordered, writing to a nonexistent nested array auto-vivifies it, reading a nonexistent key / index just evaluates to NULL and doesn’t generate an error, etc. However, I do see room for improvement.

(If you want to experiment with code examples in this post, see the reference code.)

The subject of this article is that for a long time I’ve wished for built-in functionality in PHP for dynamically accessing array elements at arbitrary nesting level. I’m talking about what are called multi-dimensional [possibly associative] arrays in PHP, and arrays / hashes / maps in other languages. In any case, I’m talking about tree structures / hierarchies built by nesting those data types. For example, consider this array:

Continue reading

Wanted: PHP core function for dynamically performing double-quoted string variable interpolation

For a long time I’ve wished PHP had a built-in function for dynamically evaluating a string variable as a double-quoted string or HEREDOC, to perform variable interpolation (aka expansion) on-the-fly. It’s frequently useful to store a template in a string and then interpolate data into it later, pass the template to a function, etc. Example:

Continue reading

How to use the same layout template(s) both with and without WordPress


Say you have a website that you want to run partly with WordPress (say a Blog section) and partly without WordPress, using the same design. I’ll demonstrate a technique for using the same layout template(s) for WordPress content and other content without duplicating code, and in the process also demonstrate that it’s not necessary to use the header & footer include scheme that WordPress advocates.

Continue reading