模型修改器
一、在模型文件中定义修改器方法
info
定义规范:get字段名Attr(字段值)
,示例,sname 字段:getSnameAttr($sname)
二、示例
示例
<?php
namespace app\models;
use core\base\Model;
class Student extends Model
{
protected $tables = 'student';
public function __construct()
{
parent::__construct($this->tables);
}
public function getSnameAttr($sname)
{
//可以对 $sname 进行处理
return '勇敢的'.$sname;
}
}
示例
$student = Student::find(1);
echo $student->sname.PHP_EOL;
$data = Student::select();
pd($data);
三、输出示例
源数据:
查询后的数据: