CakePHP without a database
Posted on June 9th, 2009
You can follow any responses to this entry through the RSS 2.0 feed.
I have started using the CakePHP MVC framework a few months ago, and it’s not too bad.
However, if you want to create a website that does not require a database connection, there’s no example or default setting.
Somehow, if you Google around you’ll find an old “MyDbo” example that isn’t working properly (at least for me) in the latest CakePHP (1.2.x)
The solution is simple, and most of us probably do this right away, but I think having an example somewhere on the net can help many people. Well, at least I hope so, so here we go:
First create the directory for the new databasource (which is, your database connector)
# mkdir app/models/datasources/dbo
Then add a file named
dbo_dummy_source.php
and fill it with all required functions for a DataSource class:
< ?php class DboDummySource extends DataSource { var $description = "This is a dummy data source"; function connect() { $this->connected = true; return $this->connected; } function disconnect() { $this->;connected = false; return !$this->connected; } function value($string) { return "\0".$string."\0"; } } ?>
Finally, just use this as datasource in CakePHP, in the file
app/config/database.php
class DATABASE_CONFIG { var $default = array( 'driver' => 'dummy_source'); }
Don’t forget to also use
var $useTables = false;
in every model.
February 17th, 2010 at 3:04 pm
This worked wonders, thanks!