cakephp数据源对未定义方法的调用
我创建了一个简单的cakephp数据源对未定义方法的调用,php,cakephp,Php,Cakephp,我创建了一个简单的数据源: // app/Model/Datasource/FeedSource.php App::uses('DataSource', 'Model/Datasource'); class FeedSource extends DataSource { public function abcd() { echo 'Hello World!'; } } 在mydatabase.php中: public $feed = array( '
数据源
:
// app/Model/Datasource/FeedSource.php
App::uses('DataSource', 'Model/Datasource');
class FeedSource extends DataSource {
public function abcd() {
echo 'Hello World!';
}
}
在mydatabase.php
中:
public $feed = array(
'datasource' => 'FeedSource'
);
在Feeda
模型中:
class Feeda extends AppModel {
public $useTable = false;
public $useDbConfig = 'feed';
}
在列表中
控制器:
$this->loadModel('Feeda');
$this->Feeda->abcd();
但是,它返回一个致命错误:
Error: Call to undefined method FeedSource::query()
如何解决
谢谢…也许你的意思是
DboSource
而不是DataSource
DataSource没有方法查询,DboSource有。将代码更新为如下所示:
App::uses('DboSource', 'Model/Datasource');
class FeedSource extends DboSource {}
编辑:看起来这不是问题所在。在模型中
有一个神奇的调用方法,它调用
$this->getDataSource()->query($method,$params,$this)代码>您需要自己实现它
class FeedSource extends DataSource {
public function abcd() {
echo 'Hello World!';
}
public function query($method, $params, $Model) {
// you may customize this to your needs.
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $params);
}
}
}
也许您的意思是DboSource
,而不是DataSource
DataSource没有方法查询,DboSource有。将代码更新为如下所示:
App::uses('DboSource', 'Model/Datasource');
class FeedSource extends DboSource {}
编辑:看起来这不是问题所在。在模型中
有一个神奇的调用方法,它调用
$this->getDataSource()->query($method,$params,$this)代码>您需要自己实现它
class FeedSource extends DataSource {
public function abcd() {
echo 'Hello World!';
}
public function query($method, $params, $Model) {
// you may customize this to your needs.
if (method_exists($this, $method)) {
return call_user_func_array(array($this, $method), $params);
}
}
}