PHP ADTP后台管理

信息系统架构

  • 信息化系统:前台 + 后台 + 数据库
  • B/S 模式
  • 前端 -> Server[Apache->PHP(TP6.0)] -> SQL DataBase
  • 运行逻辑:
    • Client发送require请求(http协议),包含header(length、refer信息)、body(数据)
    • Apache接受请求,给PHP做处理
    • PHP读取、处理数据;判断数据是否损毁、是否需要退回
    • 数据更新到前端,并返回结果(success/fail)

Think Php 6.0 MVC模式

  • MVC模式: Model View Controller
      后台            数据交互  组织查询语句
| Controller | ---> | Model | ---> | DataBase |
↓ ↖ ------------------------------ ↙
决定数据处理
| View |
前端

举例

  • 加载页面,产生一个require请求https://website.net/app_name/class_name/method_name
  • project_floder/app_name/class_name.php可以找到method_name方法
public function method_name(Request $request)
{
// 接收数据、构造请求
$attribute1 = $request->post('attribute1', 0); // body中的内容
$attribute2 = $request->post('attribute2', '');
// 处理逻辑
if(!empty($attribute1)){
$attribute = ShopLib::wxAppLogin($attribute1);
if(!$attribute) {
$errData = [
'errcode' => -2, // 相当于字典,errData['errcode'] = -2
'msg' => 'error message'
];
return json($errData);
}
}

// 到Model中查找数据
$Model = $this->getModel(); // getModel()默认使用定义的主模型,可以在common/model中找到定义
$where['key'] = [
'key_name' => $value,
];
// 处理逻辑
if(!empty($attribute)){
$where['key'] = [
'key_name' => $attribute['key_name'],
];
}
}
$Result = $Model::getDetail($where['key'], NULL);

// 组装数据
$result = [
'errcode' => 0,
'data' => $Result
];
// 返回前台
return json_encode($result);
}

  • app_name/class_name/method_name?attribute1=1&attribute2=10’?'后面的内容是参数