thinkphp5 模型读取器和修改器

方法

public function index()
{
  $ad = Destoon_ad::get(2);
  return $ad->totime;
}

模型下创建读取器

protected function getTotimeAttr($totime){
  return date('Y-m-d',$totime);
}

加入第二个参数data

protected function getTotimeAttr($totime,$data){
return $data['title'].'|'.date('Y-m-d',$totime);
}

public function index()
{
  $ad = new Ad;
  $ad->pid = '999';
  $ad->url = 'www.999.com';
  if($ad->save()){
  return $ad->aid;
  }
}

模型下创建 修改器

protected function setTotimeAttr($totime){
  return strtotime($totime);
}

原文地址:https://www.cnblogs.com/my2018/p/8849425.html