CakePHP - Tree recover()方法返回SQL错误

时间:2014-02-08 22:24:27

标签: php cakephp

我正在尝试对我的Category模型执行recover()方法,我可以使用find()等,但每当我尝试调用recover()来执行lft和rght字段更新时,它会出错以下。

错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行的'recover'附近使用正确的语法

这是一个错误还是我错过了一些明显的东西?

控制器:

class CategoryController extends AppController
{
    public function view()
    {

        // Errors
        $this->Category->recover();

                    // Works
        $this->set('category',
            $this->Category->find('first',
                array('conditions' => array('Category.id =' => $this->request->id))
            ));

    }
}

型号:

class Category extends AppModel {

}

1 个答案:

答案 0 :(得分:3)

请阅读文档 http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html

如上所述,您需要首先告诉您的模型它应该充当树(=加载行为):

class Category extends AppModel {
    public $actsAs = array('Tree');
}