在模型中加载对象,有什么问题?

Loading objects in Model, what is wrong?

我的蛋糕应用程序中有一个名为 Blurb 的对象类型,我试图将它们打印出来但出现错误:

错误:调用非对象的成员函数 find() 文件:/....../app/Model/Blurb.php
行:19

下面的代码有什么问题?

<?php
App::uses('AppModel', 'Model');

class Blurb extends AppModel {

    public $name = 'Blurb';

    public function afterSave($created, $options = array()){
        $allBlurbs = $this->Blurb->find('all');
        var_dump($allBlurbs);
        exit;
    }

}
?>

关键字 $this 引用 class Blurb 的实例,因此 $this 是 Blurb。

$this->Blurb->find('all') 的意思是 - 从实际对象获取名为 Blurb 的方法(或参数),从他进化方法 'find' 和参数 all.

如果您的 Blurb class 中有查找方法,您需要这个:

$this->find('all');