删除(真删除)很简单 ,软删除可根据实际情况修改
控制器
在User.php控制器添加删除操作
<?php
namespace app\frontend\controller;
use \tpfcore\Core;
class User extends FrontendBase
{
public function add()
{
IS_POST && $this->jump(Core::loadModel($this->name)->saveUser($this->param));
return $this->fetch("add");
}
public function edit(){
IS_POST && $this->jump(Core::loadModel($this->name)->editUser($this->param));
return $this->fetch("edit",[
"list"=>Core::loadModel($this->name)->listUser($this->param)
]);
}
public function del(){
$this->jump(Core::loadModel($this->name)->delUser($this->param));
}
}
删除逻辑logic
public function del($data){
$validate=\think\Loader::validate($this->name);
$validate_result = $validate->scene('del')->check($data);
if (!$validate_result) {
return [RESULT_ERROR, $validate->getError(),null];
}
$result=self::deleteObject($data,true);
if($result){
return [RESULT_SUCCESS, "操作成功",null];
}else{
[RESULT_ERROR, "操作失败",null];
}
}
del验证规则自己去写...
这就完成一个简单的删除功能了