ThinkPHP_5【模型获取器】

【模型获取器】

【控制器块】
namespace app\index\controller;

use think\Controller;
use app\index\model\App;

class Index extends Controller
{
public function index()
{
$res = App::get(3);
echo $res->sex;
dump($res ->toArray());
dump($res->getData());
}
}

【model块】
namespace app\index\model;

use think\Model;

class App extends Model
{
//方法名是固定的 get字段名Attr
public function getSexAttr($val)
{
switch ($val){
case '1':
return '男';
break;
case '2':
return '女';
break;
default:
return '未知';
break;
}
}
}

posted @ 2017-07-11 16:15  高锴  阅读(1358)  评论(0编辑  收藏  举报