简单cakePHP设置中的SQL错误1064

时间:2011-04-10 16:24:34

标签: sql cakephp tree

我使用的是最简单的控制器和模型,如下所示:

http://book.cakephp.org/view/1341/Basic-Usage

但是当我去www.mysite.com/categories时 导致它的代码是:

<?php
class CategoriesController extends AppController {

    var $name = 'Categories';

    function index() {
        $this->data = $this->Category->generatetreelist(null, null, null, '&nbsp;&nbsp;&nbsp;');
        debug ($this->data); die;       
    }
}
?>

我收到以下错误:

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 'recover' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Code | Context

            $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    =   "recover"
$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 'recover' at line 1"
$out    =   null

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::recover() - [internal], line ??
CategoriesController::index() - APP/controllers/categories_controller.php, line 7
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83

Query: recover

app/controllers/categories_controller.php (line 8)

我很困惑,因为我只是从原始的cakephp食谱教程中复制粘贴。

我有: 控制器/ categories_controller.php 车型/ category_model.php 并且代码是教程中的复制粘贴。

任何帮助?

2 个答案:

答案 0 :(得分:2)

问题解决了。误解模型文件。 它是:category_model.php 应该是:category.php =(

答案 1 :(得分:0)

  1. 您是否创建了类别模型?
  2. 我不确定,但我相信你应该通过指定告诉控制器你打算使用哪种型号:

    var $ name ='Categories'; var $ uses = array(“Category”);

    function index(){         $ this-&gt; data = $ this-&gt; Category-&gt; generatetreelist(null,null,null,'');         debug($ this-&gt; data);死;
        }