亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

作業(yè)作業(yè)作業(yè)作業(yè)作業(yè)作業(yè)作業(yè)

Original 2019-02-17 11:29:56 332
abstract:<?phpnamespace app\index\model;use think\Model;use think\model\concern\SoftDelete; //Trait 方法集class Tushu extends Model{ use SoftDelete; //設(shè)置數(shù)據(jù)庫字段ID名稱 protected $pk = 'id'; // 設(shè)置當(dāng)前模型對應(yīng)的完整數(shù)據(jù)

<?php

namespace app\index\model;


use think\Model;

use think\model\concern\SoftDelete; //Trait 方法集



class Tushu extends Model

{

use SoftDelete;

//設(shè)置數(shù)據(jù)庫字段ID名稱

protected $pk = 'id';

// 設(shè)置當(dāng)前模型對應(yīng)的完整數(shù)據(jù)表名稱

    protected $table = 'tushu';

    

    // 設(shè)置當(dāng)前模型的數(shù)據(jù)庫連接

    protected $connection = 'tp51';

    //軟刪除字段默認(rèn)值

    protected $defaultSoftDelete = 0;

     //軟刪除字段

    protected $deletetime = 'delete_time';

}

————————————————————————————————————————————

<?php

namespace app\index\controller;


use app\index\model\Tushu as ModelTushu;

use think\Controller;


class Tushu extends Controller

{

public function chaxun()

{

dump(ModelTushu::get(1));

//$a = ModelTushu::where('id',1)->select();

//dump($a);


//外部傳值方式

$a=$this->request->param('jiage')?:100;

$res = ModelTushu::all(function($query) use($a){

$query->where('jiage','>',$a);

});

dump($res);


}


public function tianjia()

{

$data=[

'name'=>'紅樓夢',

'jiage'=>'250'

];


ModelTushu::create($data);

}


public function gengxin()

{

$jiage=50;//  \think\Db::raw('jiage+200') 如果jiage加一個(gè)$jiage變量,怎么寫

$tiaozhengjiage=500;

ModelTushu::update(['jiage'=>\think\Db::raw('jiage+200')],function($query) use($tiaozhengjiage){

$query->where('jiage','<',$tiaozhengjiage);

});


}


public function shanchu()

{

ModelTushu::destroy(1);

ModelTushu::destroy([1,2,3]);

//閉包

ModelTushu::destroy(function($query){

    $query->where('id','>',10);

});

}


public function ruanshanchu()

{

ModelTushu::destroy(1);

//查看包括軟刪除數(shù)據(jù)

//dump(ModelTushu::withTrashed()->all());

//只看軟刪除數(shù)據(jù)

//dump(ModelTushu::onlyTrashed()->all());


}

}


Correcting teacher:西門大官人Correction time:2019-02-17 11:48:57
Teacher's summary:如果jiage加一個(gè)$jiage變量。直接寫變量就行了。注意用雙引號而不是單引號。雙引號中的php變量會解析運(yùn)行,單引號中的不會

Release Notes

Popular Entries