我写在休息api
的垫子下面的代码。ZF2 REST API编码风格(驼峰或下划线)
我认为,在验证完成控制器和编写业务逻辑和模式的业务层关心照顾的数据库操作。我希望我是正确的。
我在此澄清我是否可以将var_id
(以下划线分隔)发送到服务层或以varID
(camel-case)发送。
我搜索了很多api
的电话,其中大部分都是var_id
,这也是我用我自己的原因。
但是我怎样才能在这里使用变量,因为zend框架代码与驼峰案例,如果我为每个变量分配变量varID = var_id
,是对的。
$dataSendToService = array(
$varID = var_id,
$varID2 = var_id2;
);
我在创建方法中调用api
,如下所示。
http://128.12.788.88/api/v1/users/72
JSON get方法这样
{
"var_id":"var_value",
"var_id1":"var_value1"
}
在控制器:
function create() {
$body = $this->getRequest()->getContent();
$data = json_decode($body);
$id = $this->params('id');
//validation
if(!isset($data->pat_id) || empty($data->pat_id)) {
$resp = array(
'status' => 'failure',
'errorCode' => 531,
'errorMessage' => 'Patient ID should not be empty'
);
return new JsonModel($resp);
}
if(!isset($data->doc_id) || empty($data->doc_id)) {
$resp = array(
'status' => 'failure',
'errorCode' => 532,
'errorMessage' => 'Doctor ID should not be empty'
);
return new JsonModel($resp);
}
if(!isset($data->apt_time) || empty($data->apt_time)) {
$resp = array(
'status' => 'failure',
'errorCode' => 533,
'errorMessage' => 'Appointment time should not be empty');
return new JsonModel($resp);
}
if(!isset($data->apt_subject) || empty($data->apt_subject)) {
$resp = array(
'status' => 'failure',
'errorCode' => 534,
'errorMessage' => 'Appointment Subject time should not be empty');
return new JsonModel($resp);
}
$sm = $this->getServiceLocator();
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$usersService = new UsersService($dbAdapter);
$resp = $usersService->profile($data,$id);
}
在服务:
function create() {
//get the data and pass it to model
}
在模型:
function create() {
//get the data and insert in table and return the result
}