1. 程式人生 > >thinkphp5.0的controller、medol層的定義及呼叫的實現例項

thinkphp5.0的controller、medol層的定義及呼叫的實現例項

1、model層的設計的實現

<?php
namespace app\index\model;
use think\Model;
use think\Db;
class Member extends Model
{
   protected $table='hfs_member';

public function get_member_name($member_id){
$res=Db::table($this->table)->field("account")->where('id',$member_id)->find();
return $res['account'];

}
}

2、controller層的設計實現及呼叫model

<?php
namespace app\index\controller;
use app\index\controller\Command;

use think\Controller;

class Index extends Controller
{

     public function index()
    {

         $member=new Member();
   

//model自定義方法的呼叫
    $resGetName=$member->get_member_name(1);

    }

}