ThinkPHP_5【模型获取器】

【模型获取器】

【控制器块】
namespace appindexcontroller;

use thinkController;
use appindexmodelApp;

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

【model块】
namespace appindexmodel;

use thinkModel;

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

原文地址:https://www.cnblogs.com/Caveolae/p/7151117.html