我是 cakePHP 的初学者。收到以下错误
错误:调用非对象上的成员函数 find() 文件:/var/www/html/cakephp/app/Model/Post.php
行:11
有很多关于该错误的相关帖子,但我无法通过引用这些帖子来跟踪问题。
我的模型 Post.php
<?php
class Post extends AppModel {
public $validate = array(
'title' => array('rule' => 'notBlank'),
'body' => array('rule' => 'notBlank'));
public $belongsTo = 'Category';
public function actual(){
return $this->Post->find('all', array('conditions' => array('Post.deleted' => 0)));
}
}
?>
我在控制器中的 index()
public function index()
{
$actual = $this->Post->actual();
$this->Post->recursive = 0;
$this->paginate = array ('limit' => 5);
$this->set('actuals', $this->paginate());
}
我正在尝试实现软删除逻辑。如果用户单击删除,则数据库中已删除列中的标志将更改为 1 以获取相应的数据。因此,通常我必须显示已删除 = 0 的数据。
我可以通过在我的索引视图中放置一个 if 条件来实现它,但这很不方便,我想在模型本身过滤数据(如果可能的话)任何帮助将不胜感激。谢谢
更新 在我的模型中我改变了
return $this->Post->find
至
return $this->find
现在错误消失了,但它显示了所有数据,甚至是已删除的数据!