Loading

thinkphp5.1的公共函数库 common.php

首先引入Db类 或者是模型

use think\Db;

 

然后写公共函数

function getUserName($id){

  return Db::table('zh_user')->where('id',$id)->value('name');

}

当然了也可以套一个壳判断有没有这个函数 function_exists();

 

完整版

//根据用户主键的id,查询用户名
use think\Db;

if(!function_exists('getUserName')){
    
    function getUserName($id){
    
        return Db::table('zh_user')->where('id',$id)->value('name');
        
    }
}

 

posted @ 2019-03-29 17:32  mingBolg  阅读(547)  评论(0编辑  收藏  举报