我创建了一个简单的数据源:
// app/Model/Datasource/FeedSource.PHP
App::uses('DataSource','Model/Datasource');
class FeedSource extends DataSource {
public function abcd() {
echo 'Hello World!';
}
}
在我的database.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 {}
编辑:看起来不是问题.在模型中有一个魔术__call方法调用
$this-> getDataSource() – > query($method,$params,$this); Source您需要自己实现.
class FeedSource extends DataSource {
public function abcd() {
echo 'Hello World!';
}
public function query($method,$Model) {
// you may customize this to your needs.
if (method_exists($this,$method)) {
return call_user_func_array(array($this,$method),$params);
}
}
}