Monthly Archives: September 2009

How to use aggregation SQL functions with CakePHP

Have you ever wondering how to find MAX, MIN or AVG of a database table column in CakePHP way? Well I haven’t since yesterday. The solution is quite simple and obvious.

Lets say you want to show the average views per post (in the example we have the views field in every post).
The SQL should be something like this:

SELECT AVG(views) FROM posts

Instead of using query() function you can use the CakePHP way:

$this->Post->find('first', array('fields'=>array('AVG(views) as avg_views')));

Hope this will help someone.

New plug-in for spam protection

Today I found quite nice plug-in for WordPress pretending that it will block at least 90% of the spam attempts. Quite ambitious indeed, but the time will show.

The general idea is that this plug-in adds a stylesheet to your blog’s html source code. When a browser loads that stylesheet a cookie is dropped. If that user then leaves a comment the cookie is checked. If it doesn’t exist the comment is marked as spam.

Installation is just plug-activate-play. Let’s see what will happen.

The plug-in details page: Cookies for Comments
The authors page: Donncha O Caoimh