第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

快速入門ThinkPHP 5.0 --模型篇

難度中級
時長 3小時 0分
學(xué)習(xí)人數(shù)
綜合評分9.67
70人評價 查看評價
10.0 內(nèi)容實用
9.5 簡潔易懂
9.5 邏輯清晰
  • 使用助手函數(shù)model()獲取模型
    查看全部
    0 采集 收起 來源:什么是模型

    2018-05-12

  • 使用loader獲取模型
    查看全部
    0 采集 收起 來源:什么是模型

    2018-05-12

  • 使用model
    查看全部
    0 采集 收起 來源:什么是模型

    2018-05-12

  • 鏈?zhǔn)讲僮?
    查看全部
  • where寫法
    查看全部
  • where寫法
    查看全部
  • 輸出SQL語句
    查看全部
  • 更新數(shù)據(jù)
    查看全部
  • 插入數(shù)據(jù)
    查看全部
  • 查詢2
    查看全部
  • 查詢
    查看全部
  • 軟刪除:

    首先在模型里面引用SoftDelete
    <?php
    namespace?app\index\model;
    use?think\Model;
    use?traits\model\SoftDelete;
    class?User?extends?Model{
    ????use?SoftDelete;
    ????#autowritetimestamp表示創(chuàng)建與更新的時間戳都被打開
    ????protected?$autoWriteTimestamp?=?true;
    ????#刪除數(shù)據(jù)的時候刪除時間戳默認(rèn)寫入字段delete_time中,當(dāng)要自定義時:
    //????protected?$deleteTime?=?'自定義刪除時間字段名';
    }

    然后在控制器里面執(zhí)行操作

    <?php
    namespace?app\index\controller;
    use?think\Controller;
    use?app\index\model\User;
    class?Index?extends?Controller
    {
    ????public?function?index(){
    //????????$res?=?User::destroy(4);//被軟刪除
    //????????$res?=?User::get(2);//返回NULL
    
    ????????#查詢包含已刪除的數(shù)據(jù)
    ????????//$res?=?User::withTrashed(true)->find(2);
    
    ????????#查詢僅包含已刪除的數(shù)據(jù)
    ????????$res?=?User::onlyTrashed()->select();
    ????????foreach?($res?as?$val){
    ????????????dump($val);
    ????????}
    ????????#若要恢復(fù)被軟刪除的數(shù)據(jù),直接用update方式將delete_time的值設(shè)置為NULL即可
    
    ????????#當(dāng)開啟軟刪除后要想真正徹底刪除數(shù)據(jù),在destroy的第二個參數(shù)后面?zhèn)魅胍粋€true值
    ????????$res?=?User::destroy(1,true);
    
    ????????#通過get方式進行軟刪除/刪除
    ????????$res?=?User::get(3);//如果此處數(shù)據(jù)已經(jīng)被軟刪除則獲取到的為NULL,后面的操作無效
    ????????$user->delete();//軟刪除
    ????????$res?=?$user->delete(true);//刪除
    ????}
    }


    查看全部
  • 模型時間戳:

    <?php
    namespace?app\index\model;
    use?think\Model;
    
    class?User?extends?Model{
    ????#autowritetimestamp表示創(chuàng)建與更新的時間戳都被打開
    ????protected?$autoWriteTimestamp?=?true;
    //????#createtime為false表示創(chuàng)建的時間戳被關(guān)閉
    //????protected?$createTime?=?false;
    //????#updatetime為true表示更新時間戳被打開
    //????protected?$updateTime?=?true;
    //????#創(chuàng)建數(shù)據(jù)的時候創(chuàng)建時間戳默認(rèn)寫入字段create_time中,當(dāng)要自定義時:
    //????protected?$createTime?=?'自定義創(chuàng)建時間字段名';
    //????#更新數(shù)據(jù)的時候更新時間戳默認(rèn)寫入字段update_time中,當(dāng)要自定義時:
    //????protected?$updateTime?=?'自定義更新時間字段名';
    }


    查看全部
  • 模型修改器與自動完成

    <?php
    namespace?app\index\model;
    use?think\Model;
    class?User?extends?Model{
    ????#get+字段名+Attr
    ????public?function?getGenderAttr($val){
    ????????switch?($val){
    ????????????case?"1";
    ????????????????return?'男';
    ?????????????????break;
    ????????????case?"2";
    ?????????????????return?'女';
    ??????????????????break;
    ????????????default;
    ?????????????????return?'未知';
    ?????????????????break;
    ????????}
    ????}
    ????#模型修改
    //????public?function?setPasswordAttr($val,$data){
    //????????return?$val.$data['email'];
    //????}
    
    ????#無論對數(shù)據(jù)庫執(zhí)行插入&更新操作,總是在數(shù)據(jù)中加上time字段相應(yīng)的值
    ????protected?$auto?=?[
    ??????'time'//字段名
    ????];
    ????public?function?setTimeAttr(){
    ????????return?time();//字段對應(yīng)的值
    ????}
    
    ????#insert/update對數(shù)據(jù)庫執(zhí)行插入/更新操作時,在數(shù)據(jù)字段中加入對應(yīng)的值
    ????protected?$insert?=?[
    ????????'insert'//字段名
    ????];
    ????public?function?setInsertAttr(){
    ????????return?time();
    ????}
    }


    查看全部
  • 模型獲取器:

    首先設(shè)置User模型:

    <?php
    namespace?app\index\model;
    use?think\Model;
    class?User?extends?Model{
    ????#get+字段名+Attr
    ????public?function?getGenderAttr($val){
    ????????switch?($val){
    ????????????case?"1";
    ????????????????return?'男';
    ?????????????????break;
    ????????????case?"2";
    ?????????????????return?'女';
    ??????????????????break;
    ????????????default;
    ?????????????????return?'未知';
    ?????????????????break;
    ????????}
    ????}
    }

    然后在index控制器中操作:

    <?php
    namespace?app\index\controller;
    use?think\Controller;
    use?app\index\model\User;
    class?Index?extends?Controller
    {
    ????public?function?index(){
    ????????$res?=?User::get(1);
    ????????dump($res->gender);//獲取性別單欄數(shù)據(jù)
    ????????dump($res->toArray());//以數(shù)組形式獲取整條數(shù)據(jù),性別顯示為男/女/未知
    ????????dump($res->getData());//以原始形式獲取整條數(shù)據(jù),性別顯示為1/2/其他
    ????}
    }


    查看全部
    0 采集 收起 來源:模型獲取器

    2018-05-08

舉報

0/150
提交
取消
課程須知
1、有一定的php基礎(chǔ)。 2、對ThinkPHP5 有一定的了解。 3、沒有接觸過tp5 的學(xué)生可以先看下我之前錄制的 <快速入門 ThinkPHP5 基礎(chǔ)篇>
老師告訴你能學(xué)到什么?
1、ThinkPHP5 的數(shù)據(jù)庫操作類 2、ThinkPHP5 的數(shù)據(jù)模型 3、使用數(shù)據(jù)模型快速對數(shù)據(jù)庫進行增刪改查的操作 4、ThinkPHP5 的自動完成操作 5、模型的自動時間戳和軟刪除

微信掃碼,參與3人拼團

微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復(fù)購買,感謝您對慕課網(wǎng)的支持!