公司业务需要转学PHP,而PHP中一个功能强大且生态链完整的PHP接口框架 PhalAPI
值得大家去学习,本学习笔记持续更新!
虽然官方文档写的十分明白,以及CSDN中PhalAPI框架内容也少之又少。
因此,以自我踩坑为基础,提供一个更为精简的学习笔记,本学习笔记将会省略部分安装及简单操作。
本期内容我们来学习一下,如何在PhalAPI框架上快速应用 ADM模式实现CURD
通俗易懂的话,就是PhalAPI 框架中不采用传统的MVC架构设计模式,采用ADM开发模式!
ADM全称:Api-Domain-Model 传统MVC全称:Model-View-Controller
可见抛弃了传统的 View 层,将Controller改为Api为控制器,由此,开发设计思想产生改变
还是由Api Domain Model层进行拆分
层级处理,环环相扣的设计思想
用简单的话语讲解了关于 ADM的核心思想,那么接下来我们看看如何进行实现把!
拥有了这些我们就可以开始实现ADM下的CURD操作啦!
Insert(插入)
Update(修改)
Select(查询)
delete(删除)
Model
namespace App\Model;
use PhalApi\Exception;
use PhalApi\Model\NotORMModel as NotORM;
class Operation extends NotORM
{
protected function getTableName($id)
{
return "operation";
}
public function csdn_insert(){
$array = array("path" => "/csdn" ,"project" => "csdn");
return $this->getORM()->insert($array);
}
public function csdn_mult_insert(){
$array = array(array("path" => "/csdn2" ,"project" => "mult_csdn1"),array("path" => "/csdn3" ,"project" => "mult_csdn2"));
return $this->getORM()->insert_multi($array);
}
public function csdn_insert_update(){
$unique = array("id"=>"242");
$insert = array("path" => "/csdn2","project" => "mult_csdn1");
$update = array("path" => "/updateCsdn2");
return $this->getORM()->insert_update($unique,$insert,$update);
}
public function csdn_update(){
$updateArray = array("path" => "/csdnUpdate","project" => "csdn");
return $this->getORM()->where("id = ?",242)->update($updateArray);
}
public function csdn_update_add(){
return $this->getORM()->where("id = ?",242)->updateCounter("num",1);
}
public function csdn_update_mult_add(){
return $this->getORM()->where("id = ?",242)->updateMultiCounters(array("num"=>1));
}
public function csdn_queryAll(){
$sql = "select * from pp_operation";
return $this->getORM()->queryAll($sql);
}
public function csdn_delete(){
return $this->getORM()->where("id = ?",242)->delete();
}
}
Domain
namespace App\Domain\Operation;
use App\Model\Operation;
class OpaerationDomain
{
var $model;
public function __construct()
{
$this->model = new Operation();
}
public function csdn_insert(){
return $this->model->csdn_insert();
}
public function csdn_mult_insert(){
return $this->model->csdn_mult_insert();
}
public function csdn_insert_update(){
return $this->model->csdn_insert_update();
}
public function csdn_update(){
return $this->model->csdn_update();
}
public function csdn_update_add(){
return $this->model->csdn_update_add();
}
public function csdn_update_mult_add(){
return $this->model->csdn_update_mult_add();
}
public function csdn_queryAll(){
return $this->model->csdn_queryAll();
}
public function csdn_delete(){
return $this->model->csdn_delete();
}
}
API
namespace App\Api\Opaeration;
use PhalApi\Api;
use App\Model\Operation as Table;
use App\Domain\Operation\Permission\OpaerationPermissionDomain as PermissionDomain;
class Opaeration extends Api
{
var $domain;
var $permissionDomain;
public function __construct()
{
$this->domain = new Table();
$this->permissionDomain = new PermissionDomain();
}
public function csdn_insert(){
return $this->domain->csdn_insert();
}
public function csdn_mult_insert(){
return $this->domain->csdn_mult_insert();
}
public function csdn_insert_update(){
return $this->domain->csdn_insert_update();
}
public function csdn_update(){
return $this->domain->csdn_update();
}
public function csdn_update_add(){
return $this->domain->csdn_update_add();
}
public function csdn_update_mult_add(){
return $this->domain->csdn_update_mult_add();
}
public function csdn_queryAll(){
return $this->domain->csdn_queryAll();
}
public function csdn_delete(){
return $this->domain->csdn_delete();
}
}
就完成了ADM设计模式,同时使用了基础的NotORM的CURD方法完成该功能!
关于 PhalAPI学习笔记拓展篇 ———ADM模式中NotORM实现简单CURD 就讲到这里,对你有帮助的话!
谢谢你的观看!