Cakephp V2 without a database (Fixed)

This article is also available in the following languages:
By Primordial

This bug has now been fixed https://github.com/cakephp/cakephp/commit/6aa08b5f52955d15fb7e44ed28efcd8156c958d2

A very simple explanation on how to get around the topical bug in CakePHP V2 and use it without a database.

When you want to use CakePHP without a database create the file /app/Model/Datasource/DummySource.php with the following content

class DummySource extends DataSource {

    function connect() {
        $this->connected = true;
        return $this->connected;
    }

    function disconnect() {
        $this->connected = false;
        return !$this->connected;
    }

    function isConnected() {

        return true;
    }

}
Next update your /app/Config/database.php file altering the ‘default’ array to include a datasource that reads
'datasource' => 'DummySource'

Don’t forget, for every model you create include the property

$useTable = false

That’s all folks.

Comments

  • Posted 01/19/12 03:28:04 PM
    Thanks for the constructve feedback.

    When you install cake it prompts for a DB connection, this is a workaround I used. Can you elaborate on your comment please?

    Quote

  • Posted 01/19/12 03:11:07 PM
    This does not make any sense at all, CakePHP 2.0 will not try to perform any datbase connection unless you request it to do so. I'm leaving this article for future reference and to avoid confusion from our users.

    Quote

Please login to post a comment.