«

thinkphp5 模型新增/批量删除 闭包删除

Genius 发布于 阅读:57


控制文件:

<?php
namespace app\before\controller;
use think\Controller;
use think\Db;
use app\before\model\Article as ArticleModel;

class Article extends Controller
{

    public function Ces()
    {
      $add = new ArticleModel;
      $tj = $add->save([
          'cat_id' => 8,
          'title' => '44',
          'content' => '33',
          'author' => '22',
          'author_email' => '11',
          'keywords' => '99',
          'article_type' => 7,
          'is_open' => 6,
          'add_time' => '1533708992',
          'file_url' => 55,
          'open_type' => 4,
          'link' => 3,
          'description' => '',
          ]);
      echo $add->article_id;
    }
    public function dele(){
        //ArticleModel::destroy([212,210,211]); //删除
        ArticleModel::destroy(function($query){
            $query->where('article_id','>',200);
        });

    }

}

?>

模型文件:

<?php
namespace app\before\model;

use think\Model;

class Article extends Model
{
   protected $pk = 'article_id';

}

?>