我遇到的问题与此处和此处的问题非常相似,但这些解决方案并不能帮助我解决我的问题版本。我正在使用 CakePHP 1.3,我试图从视图控制器中调用一些模型函数:
//Class setup
var $uses = array('StudentsTelephone', 'AddressesStudent');
//...
function someFunction(){
$this->set('telephones', $this->StudentsTelephone->getActiveStudentTelepone($id));
$this->set('addresses', $this->AddressesStudent->getActiveByStudentId($id));
}
第一个模型函数调用 (StudentsTelephone) 有效,但第二个 (AddressesStudent) 失败。它尝试使用函数名作为 SQL 调用,结果如下:
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'getActiveByStudentId' at line 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
通过一点调试,我发现正在 AppModel 中查找该函数,并且从未检查过 AddressesStudent。基于这些其他解决方案,它看起来应该是名称中的错字。但是,一切似乎都正确命名。上面的代码如上所述,模型文件是addresses_student.php
,类名是 AddressesStudent 并且在我更新 Cake(最近从 1.1 切换到 1.3)之前工作正常。关于可能导致问题的任何建议不是命名错误?或者也许我错过了其他一些命名错误?非常感谢!
编辑:另外,这里的回溯告诉我从未找到模型 PHP 文件:
DboSource::showQuery() - CORE\cake\libs\model\datasources\dbo_source.php, line 684
DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php, line 266
DboSource::fetchAll() - CORE\cake\libs\model\datasources\dbo_source.php, line 410
DboSource::query() - CORE\cake\libs\model\datasources\dbo_source.php, line 364
Model::call__() - CORE\cake\libs\model\model.php, line 502
Overloadable::__call() - CORE\cake\libs\overloadable_php5.php, line 50
AppModel::getActiveByStudentId() - [internal], line ??
StudentsController::edit() - APP\controllers\students_controller.php, line 277
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 83