名字 命名 get(Price)Attr($price,$data)
Index文件
<?php namespace app\index\controller; use \app\index\model\Shop_name; class Index { public function index() { $shop = Shop_name::get(2); return $shop->price; } }
model/Shopname
<?php namespace app\index\model; use think\Model; class Shop_name extends Model { protected function getPriceAttr($price,$data) { return $data['name'].$price; } }
只需要改价格
修改器
Index
<?php namespace app\index\controller; use \app\index\model\Shop_name; class Index { public function index() { $shop = new Shop_name; $shop->name ='php'; $shop->price='12'; $shop->type='php'; if ($shop->save()){ return '保存成功'; }else{ return $shop->getError(); } }
model/Shopname
<?php namespace app\index\model; use think\Model; class Shop_name extends Model { protected function setPriceAttr($price) { return $price; } }
只需要改价格