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..
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.
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.
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;
}
}
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'
);
The third step is to be sure that $useTable = false; is included in every model, so add it in AppModel.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With