【模型获取器】

【控制器块】
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;
}
}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 1970-01-01
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案