How we setup cakephp without database?
Asked Answered
R

3

8

In few project we don't need database, so how we setup cakephp on local machine without modification in database config? Right now what I done ...I created database and modified config file. But my database has no table, its just wastage of database....so please suggest better way to do this.

Thank you in advance..

Reprography answered 16/3, 2013 at 12:16 Comment(0)
K
4

With CakePHP 2.3.x I simply use an empty string as a datasource in the database configuration and it works fine.

The database configuration (app/Config/database.php) is almost empty, it looks like this:

class DATABASE_CONFIG {
    public $default = array(
        'datasource' => '',
    );
}

You have to tell your AppModel not to use DB tables, otherwise you'll get an error: "Datasource class could not be found". It's not enough to set the $useTables in descendant models only.

class AppModel extends Model {
    public $useTable = false;
}

I dindn't experienced any problems with that yet.

Khufu answered 8/9, 2013 at 19:22 Comment(1)
Hello, class DATABASE_CONFIG { public $default = array( 'datasource' => '', ); } is my database file.Also public $useTable = false is set still it gives an error. "Datasource class could not be found. "Petiolate
C
2

Cakephp actually try to connect to a database no matter that you don’t use a table so using this

class MyModel extends AppModel {
    public $useTable = false;
}

it will be just a mistake , creating application on cakephp is piece of cake. Here are some steps you have to do in order to start developing without a database.

  1. Create fake dbo source

Create file DboFakeDboSource.php in app/Model/Datasource/Dbo/ and put the following code in it

class DboFakeDboSource extends DboSource {
  function connect() {
    $this->connected = true;
    return $this->connected;
  }
  function disconnect() {
    $this->connected = false;
    return !$this->connected;
  }
}
  1. Set the default connection

The next step is to tell cakephp to use dbo source by default. Go and change default connection in database.php to be like this

var $default = array(
  'driver' => 'FakeDboSource'
);
  1. Fine tuning the model

The third step is to be sure that $useTable = false; is included in every model, so add it in AppModel.php

Clarkin answered 8/9, 2013 at 23:25 Comment(2)
You should use App::uses('DboSource', 'Model/Datasource'); in Model, other wise gives error [Class 'DboSource' not found]Yield
am not sure yet , because this solution was tested on Cakephp 2.0Clarkin
V
0

You can just leave default datasourse settings empty in database.php and for Models you use, specify that it doesn't need corresponding table in DB like following:

class MyModel extends AppModel {
    public $useTable = false;
}
Virgy answered 16/3, 2013 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.