php mvc 模式的开发注意事项

1.控制器中:

如果不涉及到数据库的就在控制器中。

empty($res['code']) ? $this->error($res['msg']) : $this->success($res['msg']);

抛出异常写法: 

try{
$res = $Scoreflow->doaddscore($post);
if(empty($res['code'])){
throw new \Exception($res['msg']);
}
$this->success($res['msg']);
}catch(\Exception $e){
$this->error($e->getMessage());
}

2.模型中:

所有关于数据库的操作都在模型里面做。

return['code' => 0|1,'msg' => '返回信息'];//回复格式统一,会比较好处理

猜你喜欢

转载自www.cnblogs.com/roseY/p/11016399.html