我想在我的项目中实现软删除。找不到可靠的文章。以下是我得到的唯一东西..
http://www.logicsart.com/cakephp/soft-delete-in-cakephp/
无论如何,我在我的数据库中添加了相应的列,并尝试通过在我的 AppModel 中添加以下代码来实现它
public function exists($id = null) {
if ($this->Behaviors->attached('SoftDelete')) {
return $this->existsAndNotDeleted($id);
} else {
return parent::exists($id);
}
}
public function delete($id = null, $cascade = true) {
$result = parent::delete($id, $cascade);
if ($result === false && $this->Behaviors->enabled('SoftDelete')) {
return $this->field('deleted', array('deleted' => 1));
}
return $result;
}
接下来,在我的bootstrap.php
CakePlugin::loadAll();
并遵循我的模型,
public $actsAs = array('SoftDelete');
我还包含SoftDeleteBehavior.php
在 app/Model/Behavour 文件夹中。
我面临的问题是,当我在模型中包含 $actsAs 时,页面不显示任何数据,如果我排除它,软删除将不起作用。如果您有更具体的资源来实现软删除,那也会有所帮助,任何帮助将不胜感激。谢谢!