99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

tpframe之刪除數(shù)據(jù)

2018-03-23 12:09 更新

刪除(真刪除、軟刪除)很簡(jiǎn)單

一、控制器

在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)); } }

二、服務(wù)層

在service層添加User.php

<?php // +---------------------------------------------------------------------- // | Author: yaoyihong <510974211@qq.com> // +---------------------------------------------------------------------- namespace app\frontend\service;


use app\common\service\ServiceBase;
use \tpfcore\Core;
/**
 * 基礎(chǔ)服務(wù)
 */
class User extends FrontendBase
{
    public function delUser($data){
       $validate=\think\Loader::validate($this->name);
        $validate_result = $validate->scene('del')->check($data);
        if (!$validate_result) {
            return [RESULT_ERROR, $validate->getError(),null];
        }
        return Core::loadModel($this->name)->delUser($data);
    }
}

三、邏輯層

public function delUser($data){ $result=self::deleteObject($data,true); if($result){ return [RESULT_SUCCESS, "操作成功",null]; }else{ [RESULT_ERROR, "操作失敗",null]; } }

del驗(yàn)證規(guī)則自己去寫...

這就完成一個(gè)簡(jiǎn)單的刪除功能了

特別說(shuō)明

刪除分真刪除與軟刪除(改變狀態(tài)),默認(rèn)是軟刪除,狀態(tài)字段對(duì)應(yīng)的是status (0正常,-1刪除)

真刪除直接調(diào)用deleteObject(where,true)即可,where為你要?jiǎng)h除的條件

軟刪除的話第二個(gè)參數(shù)為false,但是,如果你的刪除標(biāo)識(shí)字段不是status,你就得這樣調(diào)用deleteObject(where,false,"刪除字段標(biāo)識(shí)")

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)