A dummy datasource for CakePHP

I was recently developing a project at work which at the beginning didn’t need a database. However, Cake was still testing the database connection and issuing a warning as a result when it couldn’t connect. My solution was to create a dummy datasource which silenced the warnings and allowed me to get on with the rest of development in relative peace.

The scope of the project changed and a database was required. The dummy datasource had to go so I thought I’d share it here before it was thrown to the winds.

Here’s the datasource, which belongs in models/datasources/dbo/dbo_dummy.php:

<?php
class DboDummy extends DboSource {
 
        function connect(){
                $this->connected = true;
                return true;
        }
 
        function disconnect(){
                $this->connected = false;
                return true;
        }
 
}
?>

To use the datasource use the following in your config/database.php:

<?php
class DATABASE_CONFIG {
 
        var $default = array(
                'driver' => 'dummy',
                'host' => '',
                'login' => '',
                'password' => '',
                'database' => '',
        );
 
}
?>

Enjoy!

Nano-Apps

Last month Giles Bowkett in the trawls of his hypergraphia wrote a post on Nano-Apps, quirky one page apps which serve up a piece of trivia or answer a question like is George W. Bush still president?

Previously I had put together hometi.me, a little AJAX-y app to let me know how much longer I had to go until I could leave work for the day and when a new nano-app reporting Belfast’s goodonpaper‘s coffee drinking habits surfaced the bug bit me and I wanted to do something and do it quick.

I had the embryo of an idea on a Sunday and had production code on the following Saturday morning.

The app attempts to answer the question is it raining in Belfast? by scraping the MET office forecast for Belfast and sometimes gets it right. It has a Ruby back-end and PHP front-end and is available on GitHub for anyone interested. The graphics need tweaked and it would no doubt be better displaying the weather that was previously forecast for the current time period, but it’s out there doing it’s thing which was the point in the exercise.

During this process something that caught my eye is Sinatra, a Ruby framework suited to creating web-apps with minimal code. Now all I need is a idea to implement with it…