Dear Community, Not sure if this is the right place, but here goes. I've upgraded an application from 1.3.10 to 2.0.0 and now get the following error:
"Fatal error: Access to undeclared static property: DboSource:: $methodCache in /var/www/html/myapp/lib/Cake/Model/Datasource/ DboSource.php on line 3090" I'm using a master-slave setup and have modified the AppModel callbacks appropriately (as explained on one of the bakery pages). For Cake 1.3 this works nicely, but on 2.0 I get the error above. I have modified the cake code (I know I shouldn't :-) ) as follows: Index: /var/www/html/myapp/lib/Cake/Model/Datasource/DboSource.php =================================================================== --- /var/www/html/myapp/lib/Cake/Model/Datasource/DboSource.php +++ /var/www/html/myapp/lib/Cake/Model/Datasource/DboSource.php @@ -3087,6 +3087,9 @@ */ public function __destruct() { if ($this->_methodCacheChange) { + if (empty(self::$methodCache)) { + self::$methodCache = Cache::read('method_cache', '_cake_core_'); + } Cache::write('method_cache', self:: $methodCache, '_cake_core_'); } } This solved the problem and I no longer get the messages. Is this a bug and is my fix above the correct solution? Many thanks in advance! Kind regards, Derik app/Model/AppModel.php <?php class AppModel extends Model { public function __construct($id = false, $table = null, $ds = null) { // If a datasource is set via params, use it and return if ((is_array($id) && isset($id['ds'])) || $ds) { parent::__construct($id, $table, $ds); return; } // Use a static variable, to only use one connection per page-call (otherwise we would get a new handle every time a Model is created) static $_useDbConfig; if (!isset($_useDbConfig)) { // Get all available database-configs $sources_list = ConnectionManager::enumConnectionObjects(); // Find the slaves we have $slaves = array(); foreach ($sources_list as $name => $values) { // Slaves have to be named "slave1", "slave2", etc... if (preg_match('/^slave[0-9]*+$/i', $name) == 1) { $slaves[] = $name; } } if (count($slaves) > 0) { // Randomly use a slave $_useDbConfig = $slaves[rand(0, count($slaves) - 1)]; } else { $_useDbConfig = "default"; } } $this->useDbConfig = $_useDbConfig; parent::__construct($id, $table, $ds); } function save($data = null, $validate = true, $fieldList = array()) { $oldDb = $this->useDbConfig; $this->setDataSource("master"); if (isset($this->data) && isset($this->data[$this- >name])) unset($this->data[$this->name]['modified']); if (isset($data) && isset($data[$this->name])) unset($data[$this->name]['modified']); $isSave = parent::save($data, $validate, $fieldList); $this->setDataSource($oldDb); return $isSave; } function saveAll($data = null, $options = array()) { $oldDb = $this->useDbConfig; $this->setDataSource("master"); if (isset($this->data) && isset($this->data[$this- >name])) unset($this->data[$this->name]['modified']); if (isset($data) && isset($data[$this->name])) unset($data[$this->name]['modified']); $isSave = parent::save($data, $options); $this->setDataSource($oldDb); return $isSave; } function updateAll($fields, $conditions=true) { $oldDb = $this->useDbConfig; $this->setDataSource("master"); if (isset($this->data) && isset($this->data[$this- >name])) unset($this->data[$this->name]['modified']); if (isset($data) && isset($data[$this->name])) unset($data[$this->name]['modified']); $isUpdated = parent::updateAll($fields, $conditions); $this->setDataSource($oldDb); return $isUpdated; } function delete($id = null, $cascade = true) { $oldDb = $this->useDbConfig; $this->setDataSource("master"); $isDeleted = parent::delete($id, $cascade); $this->setDataSource($oldDb); return $isDeleted; } function deleteAll($conditions, $cascade = true, $callbacks = false) { $oldDb = $this->useDbConfig; $this->setDataSource("master"); $isDeleted = parent::deleteAll($conditions, $cascade, $callbacks); $this->setDataSource($oldDb); return $isDeleted; } function current_user() { App::import('Component','Session'); $Session = new SessionComponent(); return array('id'=>$Session->read('Authacl.id')); } } ?> and my app/Config/database.php: class DATABASE_CONFIG { /* default = master, e.g. for sessions and if you don't have app/views/pages/home.ctp you need it too */ var $default = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'port' => '', 'login' => 'root', 'password' => '', 'database' => 'mydb', 'schema' => '', 'prefix' => '', 'encoding' => '' ); var $master = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'port' => '', 'login' => 'root', 'password' => '', 'database' => 'mydb', 'schema' => '', 'prefix' => '', 'encoding' => '' ); /* slaves, can also be slave1, slave2, ... and then random one will be chosen - read only */ var $slave = array( 'datasource' => 'Database/Mysql', 'persistent' => false, 'host' => 'localhost', 'port' => '', 'login' => 'root', 'password' => '', 'database' => 'mydb', 'schema' => '', 'prefix' => '', 'encoding' => '' ); } -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php