How do we configure cakephp without a database?

In several projects, we do not need a database, since we configure cakephp on the local computer without changing the database configuration? Right now, what I did ... I created a database and changed the configuration file. But my database does not have a table, its just losing the database .... so please suggest a better way to do this.

Thanks in advance.

+6
source share
3 answers

With CakePHP 2.3.x, I just use the empty string as the data source in the database configuration, and it works great.

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

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

You must tell the AppModel not to use the database tables, otherwise you will receive an error message: "Datasource class not found." This is not enough to set $ useTables only in streaming models.

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

I have not experienced any problems with this yet.

+4
source

Cakephp is actually trying to connect to the database no matter what table you are using therefore using this

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

it will just be a mistake, creating a cakephp application is a piece of cake. Here are some steps you need to take to start development without a database.

  • Create Source Source dbo

Create the file DboFakeDboSource.php in the application / 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; } } 
  • Set default connection

The next step is to specify that cakephp uses the default dbo source. Go and change the default connection in database.php this way

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

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

+2
source

You can simply leave the default datasourse settings empty in the database.php file and, for the models you use, indicate that the DB does not have a corresponding table, for example:

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

All Articles