better error message in MissingConnectionException when driver is not enabled

This commit is contained in:
Ceeram 2012-06-15 14:51:36 +02:00
parent 55f3cbe1f6
commit b913fe5303
5 changed files with 21 additions and 7 deletions

View file

@ -337,6 +337,12 @@ class MissingConnectionException extends CakeException {
protected $_messageTemplate = 'Database connection "%s" is missing, or could not be created.';
public function __construct($message, $code = 500) {
if (is_array($message)) {
$message += array('enabled' => true);
}
parent::__construct($message, $code);
}
}
/**

View file

@ -237,7 +237,8 @@ class DboSource extends DataSource {
$this->fullDebug = Configure::read('debug') > 1;
if (!$this->enabled()) {
throw new MissingConnectionException(array(
'class' => get_class($this)
'class' => get_class($this),
'enabled' => false
));
}
if ($autoConnect) {

View file

@ -3429,10 +3429,6 @@ class Model extends Object implements CakeEventListener {
}
$this->schemaName = $db->getSchemaName();
if (empty($db) || !is_object($db)) {
throw new MissingConnectionException(array('class' => $this->name));
}
}
/**

View file

@ -559,6 +559,15 @@ class ExceptionRendererTest extends CakeTestCase {
),
500
),
array(
new MissingConnectionException(array('class' => 'Mysql', 'enabled' => false)),
array(
'/<h2>Missing Database Connection<\/h2>/',
'/Mysql requires a database connection/',
'/Mysql driver is NOT enabled/'
),
500
),
array(
new MissingDatasourceConfigException(array('config' => 'default')),
array(

View file

@ -21,10 +21,12 @@
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', '%s requires a database connection', $class); ?>
</p>
<?php if (!$enabled) : ?>
<p class="error">
<strong><?php echo __d('cake_dev', 'Error'); ?>: </strong>
<?php echo __d('cake_dev', 'Confirm you have created the file : %s.', APP_DIR . DS . 'Config' . DS . 'database.php'); ?>
<?php echo __d('cake_dev', '%s driver is NOT enabled', $class); ?>
</p>
<?php endif; ?>
<p class="notice">
<strong><?php echo __d('cake_dev', 'Notice'); ?>: </strong>
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s.', APP_DIR . DS . 'View' . DS . 'Errors' . DS . basename(__FILE__)); ?>