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

posted @ 2018-04-15 20:56  我是谁,我在做什么  阅读(142)  评论(0编辑  收藏  举报