写thinkphp6的模型获取器
controller文件
<?PHP namespace app\index\controller; use app\BaseController; use app\index\model\Admins; class Index extends BaseController { public function index() { $db = new Admins(); $index = $db->index(); print_r($index->status); print_r($index->time); } }
点击 "运行实例" 按钮查看在线实例
模型文件
<?php namespace app\index\model; use think\Model; class Admins extends Model{ public function index(){ $user = Admins::find(1); // echo $user->status; // echo $user->time; return $user; } public function getStatusAttr($v){ $status = [0=>'禁用',1=>'开启']; return $status[$v]; } public function getTimeAttr($v){ return $v; } }
点击 "运行实例" 按钮查看在线实例