准备条件 下载thinkphp5框架[http://www.thinkphp.cn/](http://www.thinkphp.cn/) 模型 ~~~ <?php namespace app\model; use think\Model; class Placard extends Model { // 定义时间戳字段名 protected $autoWriteTimestamp = true;// 关闭自动写入时间戳 } ~~~ 验证机制 ~~~ <?php namespace app\common\validate; use think\Validate; class Placard extends Validate{ protected $rule=[ ]; protected $message=[ ]; /** * 自定义验证规则 * @param $value * @return bool */ protected function checkPhone($value) { return preg_match("/^1[0345789]{1}\d{9}$/",$value)?true:false; } } ~~~ 增加操作 ~~~ function add(){ $data['agent_id']= input('agent_id'); $data['textarea']= input('textarea'); $validate_result = $this->validate($data,'Placard'); if ($validate_result!==true){ $this->error($validate_result); }else{ if (PlacardMoble::create($data)){ $this->success('发布成功'); }else{ $this->error('发布失败'); } } } ~~~ 修改操作 ~~~ public function update() { $placard = PlacardMoble::get(11); $placard->agent_id=1; $placard->textarea=33; $validate_result = $this->validate($placard,'Placard'); if ($validate_result!==true){ $this->error($validate_result); }else{ if ( $placard->save()){ $this->success('更新成功'); }else{ $this->error('更新失败'); } } } ~~~ 删除操作 ~~~ public function del($id){ if ( @PlacardMoble::get($id)->delete()){ $this->success('删除成功'); }else{ $this->error('删除失败'); } } ~~~