Open goofy-he opened 5 years ago
class AdvModel extends Model { protected $name = 'adv'; protected $type = [ 'pics_detail' => 'array', 'valid_time' => 'datetime', ];
实例化模型时插入数据,新增不上 $add = new AdvModel([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]); $add->save(); 实例化后插入可以 $add = new AdvModel(); $add->save([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]);
$add = new AdvModel([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]); $add->save();
$add = new AdvModel(); $add->save([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]);
实例化的时候传入的数据被认为是实际的数据,是不会经过修改器处理的,所以类型定义无效
class AdvModel extends Model { protected $name = 'adv'; protected $type = [ 'pics_detail' => 'array', 'valid_time' => 'datetime', ];
实例化模型时插入数据,新增不上
$add = new AdvModel([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]); $add->save();
实例化后插入可以$add = new AdvModel(); $add->save([ 'pics_detail'=> [ 'http://img95.699pic.com/photo/40100/4686.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/4859.gif_wh300.gif', 'http://img95.699pic.com/photo/40100/7270.gif_wh300.gif' ], ]);