How to: Namespace in PHP

Namespacing has been long awaited to enhance PHP OO development, and it looks like it's finally here. At first, I thought it was going to become available in PHP6, but it has been ported to PHP 5.3.

What is a Namespace?

Namespacing provides you the freedom to name your classes what you want without worrying about any other classes, native to PHP or otherwise, interfering with your names.

PHP foreach value by reference

[img_assist|nid=9|title=|desc=|link=none|align=right|width=100|height=66] PHP5 added a very subtle yet very handy feature in the foreach Control Structure. It is the ability to access the value in the iteration as a reference to the original array.

The best way to demonstrate this is to establish an objective.

Objective: Write a function to capitalize all elements of an array.

JQuery Sortables with PHP and MySQL

[img_assist|nid=10|title=|desc=|link=none|align=right|width=100|height=71]This article will show you how to order a server-side list of fruit from a database using drag and drop behavior and then save them back to the database in order.

I recently worked on a project which required an unordered list to be re-ordered and then saved. I wasn't about to make users enter numbers next to each item so I looked toward JQuery's UI library.

Objective: We will display a list of fruit. The user can then drag the fruit and click a button to save the new order in the database.

An alternative to Pathauto

Pathauto is an awesome module, but there may be a time when, for one reason or another, don't want or don't need to use it.

custom_url_rewrite is a function (not a hook) available in Drupal which gives you an alternative to configuring custom paths and storing them in the database.

Since this is not a hook, it is suggested you put this in settings.php. You can convert the alias into the source, and vice versa.

Theming the Drupal flashvideo module with swfobject.

[img_assist|nid=11|title=|desc=|link=none|align=right|width=87|height=100]The FlashVideo module is great, but you may want to embed the video with swfobject, so here's one way to do it.

Of course for this to work you're going to need to include swfobject.js in your template. How you do that depends on your theme and is a little beyond the scope of this article.