CakePHP's array datasource

The ArraySource is a read-only datasource for CakePHP's ORM which uses an array of records inside the Model classes. It was originally created by Juan Basso a couple of years ago. Since then it has been moved to the official CakePHP Datasources plugin and is compatible up to version 2.4.

It is pretty useful for things like statuses, genders or countries for example. These things are usually static and therefor ideal to move out of the database. Using the ArraySource you would still be able to use them in associations and they will be merged in when you do a find. It works with Containable as well. So it's a good replacement for ENUMs, which aren't supported by CakePHP.

Continue reading...

GIT commit messages

It often happens that I read through GIT logs. It is a great way to check how a project is progressing. You can easily see when features were implemented and bugs were fixed. Unfortunately the logs are pretty useless when commits are randomly done and messages are too fuzzy to make something out.

I recently saw a list of 5 commits by the same author. All with the same commit message: "Modified files.". All had a bunch of files changed without any indication what was really going on. This is obviously wrong and it pisses me off. Not everybody seems to understand the value of a proper commit with a proper message. So I am going to explain some things and give a few tips.

Continue reading...

Routing isolation in CakePHP

We always preach (in the IRC channel #cakephp) to add routing when you are done developing your application. In reality though, it isn’t always that easy if you are following the book. Routing isn’t just changing the routes, sometimes it is also changing the links across your site. It could even be worse if a value is needed in the URL that isn’t yet available. You will end up changing your model code as well to get it from the database. You know routes and links like these:

<?php
Router::connect(
    '/post/:slug',
    array('controller' => 'posts', 'action' => 'show'),
    array('pass' => array('slug'))
);
?>
<?php
echo $this->Html->link('Routing isolation in CakePHP', array(
    'action' => 'show', 
    'slug' => $slug
));
?>

Another problem with this is that you have values in your links that when removed from the route turn into named parameters. You will get something like /post/slug:routing-isolation-in-cakephp. So you end up changing your views again. The problems don’t end here though.

Continue reading...

Being called a programmer

Let’s start out with the definition of a programmer.

pro•gram•mer [proh-gram-er] noun

  1. a person who writes computer programs; a person who programs a device, especially a computer.
  2. a person who prepares program schedules, as for radio or television.
  3. a person who prepares instructional programs.

The latter two definitions aren’t really relevant in this context. The first is the one I want to talk about. A person who writes computer programs is what I am. That doesn’t quite cover it though. I like to call myself a software developer, because I’m not coding day in, day out. Most of the time I solve problems. Some problems are simple and others need a bit more thought. For example, instead of programming, I first find the right tool for the job. That makes sense, but how often does it happen someone picks something they have experience with, without looking at the options?

Continue reading...