Generic collections in PHP

Tags:

Today while reading PHP::Impact’s refactoring guideline post I was reminded about collections. As you probably know, arrays are very flexible in PHP and probably a good choice for many data storing tasks. Strictly typed languages usually use “generic” collection classes instead of arrays. They are kind of like PHP arrays which the programmer can tell which type of items to …

Theory vs. Practice in coding

Tags:

When working on a project, I sometimes find myself stuck – thinking about some implementation detail, such as how to tell my admin-module which other modules are installed in my CMS (but that’s another story) – and being stuck, unable to get anything done, just thinking of the problem at hand, because I want to find the best possible way …

More on extensible authentication/access control

Tags:

Two weeks ago, I mentioned an easy way to create easily changeable ways for authenticating users. Continuing on that, I’ve been implementing ways to control user roles and user access for specific pages and modules in my CMS. Naturally, those features too are designed to be easily modifiable. An ACL factory A RoleProvider singleton You might not know what those …

Understanding Doctrine’s NestedSet feature

Tags:

The Doctrine library comes with a feature called nested set, which makes saving trees in a database easy. However, it’s quite easy to accidentally cause a lot of extra unneeded queries if not being careful. Here are some pointers to keep in mind while working with the nested set, and some example queries to make understanding it easier.

Database helper for PHPUnit

Tags:

When testing code which uses the database, you would usually want to make sure the database stays pristine for each test – All tables should be empty, as any extra data could interfere with the tests. You could probably write an extended Testcase class which automatically does this before each test in setUp and afterwards in tearDown, but it may …

Zend_Form decorator tips

Tags:

It seems a lot of people are struggling with Zend_Form decorators. They want to know how to modify the markup, but they can’t figure out how to do it with the bundled decorators or how to write their own. Since I’ve done some decorator-stuff myself, I thought I’d share some tips on making the output a bit nicer. For example, …

PRADO: PHP goes ASP.NET (ish)

Tags:

Lately, I’ve been checking out PRADO, which is “a component-based and event-driven programming framework for developing Web applications in PHP 5”. What that actually means is that you can use components, such as a data grid or a button, and work with them based on events without having to think about the traditional things associated with such: Parsing out POST …

View inheritance and “blocks” in Zend_View

Tags:

Some frameworks like Django and PRADO have the concept of view inheritance, or a “master page” like in ASP.NET. Essentially it’s a similar idea as Zend_Layout is in Zend Framework, but the difference is that you can define the master/parent view inside the view itself. For example, in Django {% extends “base.html” %} would make the current template extend “base.html”, …

Setting up command-line PHP on Windows

Tags:

On *nix systems you usually have the php executable available in shell, so you can run command-line scripts like unit tests and such, but on Windows this isn’t usually the case. Let’s fix that! There’s two ways to do this: Temporary and permanent