I've just installed CakePHP 2.0.2 for use in a new project. I'm trying to use a database configuration called development
but my model doesn't seem to be picking it up.
Based on CakePHP 2's new directory and file name conventions, I've created the following at /app/Model/AppModel.php
:
<?php
class AppModel extends Model {
public $useDbConfig = 'development';
}
However, the default home page tells me:
Cake is NOT able to connect to the database.
Yet if I change the configuration name in /app/Config/database.php
to default
the message changes to a success message, as though it's not picking up my custom AppModel
class.
How can I remedy this? As the new CakePHP 2.0 docs say to use the $useDbConfig
property as I have done above?
EDIT: Contents of /app/Config/database.php
:
class DATABASE_CONFIG {
public $development = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'cakephp_db',
'prefix' => '',
'encoding' => 'utf8',
);
}
Like dhofstet has explained, you still need to have a default config. What I do is add a constructor to the DATABASE_CONFIG class to switch between database configs.
Something like this...
public function __construct()
{
if (DEV_SERVER) {
$this->default = $this->development;
} else {
$this->default = $this->production;
}
}