Reputation: 1241
I'm trying to develop an application that does not use a database, but that still has some models.
First problem: Cake look however for the configuration of the database (APP/Lib/Cake/Model/ConnectionManager.php, line 69), it tries to include the file Config/database.php.
If the file doesn't exist, I get 2 warnings. If it exists (even if it is completely empty) all ok. I want to clarify that this takes place even in the absence of models.
Second problem: if I try to use a model, I get the error:
Missing Datasource Configuration
Error: The datasource configuration default was not found in database.php.
This happens whether the Config/database.php file exists, whether the file is not present.
Finally, I specify that models (including the AppModel) have the property $useTable set to false, but it seems that it makes no difference.
But I have noticed that everything works correctly when in an application that uses a database there are only a few models that do not use it (but the app as a whole uses it).
I found this which proposes a solution, which then is the solution that is found on the web.
But below, in the comments, I read that Lorenzo says:
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
It seems to me that it has not, maybe CakePHP does not perform any query but still want a database is configured. Is that so? Or I missed something?
Thank you.
Upvotes: 2
Views: 3402
Reputation: 29007
CakePHP doesn't try to connect to the database until it is actually required, however;
__call()
method; This method will first check if a Behavior is able to handle the call, and otherwise will make a call to the database. E.g. using $this->Mymodel->doSomething()
will cause CakePHP to attempt to open a database connection and execute doSomething
in the database. Model
, using schema information from the database, causing a connection to be opened.Example
class PostsController extends AppController {
// This controller does not use a Model
public $uses = false;
public function index() {
// CakePHP will construct a 'Post' model here
$this->Post->find('something');
}
}
Having said that. In most cases, it's best to have your models use a datasource; A datasource does not have to be a database, but may also be, for example, a Twitter Feed
or a static Array()
.
Having a datasource simplifies most tasks (e.g. you can just perform find(....)
to get the data from your source, whether that is a database or not.
Upvotes: 4