Created
January 30, 2012 01:58
-
-
Save krolow/1701931 to your computer and use it in GitHub Desktop.
AppModel.php for CakePHP projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Model', 'Model'); | |
class AppModel extends Model { | |
public $actsAs = array('Containable'); | |
public $recursive = -1; | |
public function getErrors() { | |
return $this->validationErrors; | |
} | |
public function errorsToJSON() { | |
$errors = array(); | |
foreach ($this->validationErrors as $key => $message) { | |
$errors['data[' . $this->name . '][' . $key . ']'] = $message; | |
} | |
return $errors; | |
} | |
public function getLog() { | |
$logs = array(); | |
$dbConfigs = ConnectionManager::sourceList(); | |
foreach ($dbConfigs as $configName) { | |
$driver = null; | |
$db = ConnectionManager::getDataSource($configName); | |
$logs += $db->getLog(); | |
} | |
if (isset($logs['log'])) { | |
$return = array(); | |
foreach ($logs['log'] as $log) { | |
$return[] = $log['query']; | |
} | |
} | |
return $return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment