我创建了一个简单的datasource:
// 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';
}
在list控制器中:
$this->loadModel('Feeda');
$this->Feeda->abcd();
但是,它返回一个致命错误:
But, it returns a fatal error:
Error: Call to undefined method FeedSource::query()
如何解决?
谢谢...
也许你的意思是 DboSource 而不是 DataSource.
Perhaps you meant DboSource instead of DataSource.
DataSource 没有方法查询,DboSource 有.将您的代码更新为:
DataSource has no method query, DboSource does. Update your code to look like:
App::uses('DboSource', 'Model/Datasource');
class FeedSource extends DboSource {}
看起来这不是问题.在 Model 中有一个神奇的 __call 方法,它调用$this->getDataSource()->query($method, $params, $this); 来源你需要自己实现这个.
Looks like that is not the issue. In the Model there is a magic __call method which calls
$this->getDataSource()->query($method, $params, $this); Source You need to implement this yourself.
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);
}
}
}
这篇关于cakephp 数据源调用未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
不能使用 'Object 作为类名,因为它是保留的Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作为类名,因为它是保留的 Cake 2.2.x)
OAuth 重定向后会话丢失Session is lost after an OAuth redirect(OAuth 重定向后会话丢失)
Cakephp 3.x 中的分页排序Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分页排序)
CakePHP 多个应用程序的共享核心CakePHP Shared core for multiple apps(CakePHP 多个应用程序的共享核心)
在 CakePHP 3 上登录 [ Auth->identify() ] 始终为 falLogin [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登录 [ Auth-identify() ] 始终为 false)
致命错误:允许的内存大小为 134217728 字节已用尽Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命错误:允许的内存大小为 134217728 字节已用尽