Ruby on Rails (”Rails”) is a great development platform because it is specifically designed for rapid development, deployment, and maintenance of database-driven websites. But what if you are still using PHP and you are not ready or able to switch to Rails? Luckily, a lot of the concepts that are built into Rails are also good concepts to keep in mind when using PHP.
In this multi-part series, I will illustrate the use of some Rails principles in the PHP world.
Principle: Convention (default behavior that is expected)
Rails stresses conventions. An often-used Rails expression is “convention over configuration.” For example, Rails expects files to be named in certain ways and placed in certain directories. This keeps everything organized and clean. Are you sticking to any conventions with your PHP projects? You may find that taking some time to simply rename and organize your project files can do wonders for your productivity and ease in maintenance.
Consider for example, if you are developing a project to keep track of an automobile dealer’s inventory. Your users will need to see a list of available cars, maybe search by model or color, and then be able to click on a listing for more details, including the price and the vehicle identification number, and finally, they will need to edit or delete individual listings. Even if you are not that familiar with MVC programming, you will notice that your user will have 3 basic “views” of the inventory: (1) an overall listing of all cars, (2) a detail look at a single car listing and (3) a detail look at a single car listing that can be edited. The common aspect of all these “views” is cars, right? So, you may want to create a subdirectory called “cars” and within that directory name your scripts to handle the task of each of these: “list.php”, “detail.php” and “edit.php”.
Next, you will probably need to keep track of users for this system, including their names and passwords. As with the “cars” subdirectory, you might consider creating a “users” subdirectory with “list.php”, “detail.php” and “edit.php” to handle the tasks of working with the authorized users for the system.
Now, imagine the ease of using URL’s like “cars/list.php” or “users/list.php”. Likewise, imagine the simplicity of working with “cars/detail.php?VIN=AS1223827″ or “users/edit.php?name=Tom”.
It may seem simple, but a lot of PHP programmers do not create logical subdirectories based around the “objects” of their application. In our example, the objects were cars and users. When you work on your next PHP project, try and stick to some conventions for your project. That way, you may not only simplfy your development, but also ease your maintenance down the road when you’ve long forgotten all the details.
Next time, we’ll explore another aspect of Rails and how it can apply to PHP development.
![]() Bookmark on del.icio.us |

Recent Comments