ConnectionManager getDataSource undefined method

Using cakephp 2.3.8 I am trying to connect to a couchbase user data source that I made in another data source. The data source that I am trying to load functions on the rest of the site when loading through the model. I want to use the connection manager to load this data source. This is what I have so far:

database.php file:

public $queriesCB = array( 'datasource' => 'CouchbaseSource', 'username' => 'queries', 'password' => '', 'bucket' => 'queries', 'prefix' => 'q_', 'expiry' => '1814400', //3 Weeks 'autoConnect' => true, 'database' => NULL , 'persistent' => false ); 

In my other data source trying to load datasource couchbase

 $db = ConnectionManager::getDataSource("queriesCB"); 

When I debug $ db, I get the following:

 object(CouchbaseSource) { description => 'Couchbase DataSource' conObject => object(Couchbase) { [private] _handle => resource } config => array( 'password' => '*****', 'database' => '*****', 'prefix' => '*****', 'datasource' => 'CouchbaseSource', 'username' => 'queries', 'bucket' => 'queries', 'expiry' => '1814400', 'autoConnect' => true, 'persistent' => false ) prefix => 'q__' connected => false cacheSources => true configKeyName => 'queriesCB' [protected] _baseConfig => array() [protected] _descriptions => array() [protected] _sources => null [protected] _transactionStarted => false } 

Now, when I try to call this, I get an error message:

 $db = ConnectionManager::getDataSource("queriesCB"); $db->Get('test'); 

Error: calling the undefined method CouchbaseSource :: Get ().

This is a custom method, the data source is common to work best with couchbase, and the Get method works correctly. How do I set this connection incorrectly in cakephp?

Edit:

I just tested it with the default database configuration in mysql database, and that didn't work either. The question now is, what would be the best way to initialize a new data source? Should I load a model with this data source attached? Example: have a couchbase model with a data source like couchbase?

Edit: Here are some of the data sources.

 class CouchbaseSource extends DataSource { public $description = 'Couchbase DataSource'; public $conObject = NULL; public $config = NULL; public $prefix = NULL; public function __construct($config = array()){ // If no configuration is set we use the default $this->config = $config; // Setup the cache string that is used when building the string $this->prefix = (isset($this->config['prefix']) ? $this->config['prefix']."_" : ""); if ($this->config['autoConnect']) { $this->connect(); } } public function connect() { if ($this->conObject !== true) { try { $this->conObject = new Couchbase("127.0.0.1:8091", $this->config['username'], $this->config['password'], $this->config['bucket'], $this->config['persistent']); } catch (Exception $e) { throw new MissingConnectionException(array('class' => $e->getMessage())); } } return $this->conObject; } public function query($method, $params, $object) { // If not connected... reconnect! if(!$this->conObject) { $this->connect(); } $apiMethod = $this->__methodToClass($method); if (!method_exists($this, $apiMethod)) { throw new NotFoundException("Class '{$apiMethod}' was not found"); } else { return call_user_func_array(array($this, $apiMethod), $params); } } private function __methodToClass($method) { return 'CB' . strtolower(Inflector::camelize($method)); } public function describe(&$Model) { return $this->description; } ///////////////////////////////////////////////// // Query Methods ///////////////////////////////////////////////// public function CBadd($key = NULL, $value = NULL, $expiry = NULL, $persisto = NULL, $replicateto = NULL) { return $this->conObject->add($key, $value, $expiry, $persisto, $replicateto); } 
0
source share
1 answer

The solution is to directly call the request method from couchbasesource. Given the way to configure the data source, in contrast to binding it to the model, the request information was not automatically transmitted. I went around this just to use it.

 App::uses('ConnectionManager', 'Model'); $db = ConnectionManager::getDataSource("queriesCB"); debug($db->query('Get', array('test'))); 
+2
source

All Articles