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;
}
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM