У меня есть две таблицы, Pages и Posts, которые находятся в HABTM и объединены с помощью таблицы присоединения pages_posts.
Модель моей страницы вместе с определением HABTM содержит функцию.
class Page extends AppModel
{
var $name = "Page";
......
......
function callthis()
{
return $this->find('all');;
}
}
С моего контроллера сообщений я пытаюсь вызвать эту функцию ..
class PostsController extends AppController
{
....
....
function index()
{
$returned = $this->Post->Page->callthis();
}
}
В результате
Warning (512): 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 'threadedpages' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 681]
Дополнительные выходные данные отладки:
Код
$out = null;
if ($error) {
trigger_error('<span style="color:Red;text-align:left"><b>' . __('SQL Error:', true) . "</b> {$this->error}</span>", E_USER_WARNING);
Контекст
$sql = "threadedpages"
$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 'threadedpages' at line 1"
$out = null
Звонки
DboSource::showQuery() - CORE/cake/libs/model/datasources/dbo_source.php, line 681
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::threadedpages() - [internal], line ??
PostsController::admin_index() - CORE/plugins/cakey/controllers/posts_controller.php, line 11
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
Вызов связанной функции модели должен быть возможен в CakePHP, верно? Если мы проверяем http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM, Мы можем видеть, что
$this->Recipe->Tag->find('all', array('conditions'=>array('Tag.name'=>'Dessert')));
Когда функция find () модели Tag может вызываться из соответствующего контроллера Recipes, почему я не могу вызвать функцию callthis () модели Page из связанного контроллера Posts?