forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFieldController.php
More file actions
executable file
·86 lines (55 loc) · 2.01 KB
/
Copy pathFieldController.php
File metadata and controls
executable file
·86 lines (55 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace app\controllers\home;
use Yii;
use yii\web\Response;
use app\models\api\UpdateField;
/**
* Site controller
*/
class FieldController extends PublicController
{
/**
* 更新表单
* @param $id
* @return array|string
*/
public function actionForm($api_id)
{
$request = Yii::$app->request;
$api = UpdateField::findModel(['encode_id' => $api_id]);
if($request->isPost){
Yii::$app->response->format = Response::FORMAT_JSON;
if(!$api->load($request->post())){
return ['status' => 'error', 'message' => '数据加载失败'];
}
if ($api->store()) {
$callback = url('home/api/show', ['id' => $api->encode_id]);
return ['status' => 'success', 'message' => '编辑成功', 'callback' => $callback];
}
return ['status' => 'error', 'message' => $api->getErrorMessage(), 'label' => $api->getErrorLabel()];
}
return $this->display('/home/field/form', ['api' => $api, 'project' => $api->project]);
}
/**
* 更新JSON
* @param $api_id
* @return array|string
*/
public function actionJson($api_id)
{
$request = Yii::$app->request;
$api = UpdateField::findModel(['encode_id' => $api_id]);
if($request->isPost){
Yii::$app->response->format = Response::FORMAT_JSON;
if(!$api->load($request->post())){
return ['status' => 'error', 'message' => '数据加载失败'];
}
if ($api->store()) {
$callback = url('home/api/show', ['id' => $api->encode_id]);
return ['status' => 'success', 'message' => '编辑成功', 'callback' => $callback];
}
return ['status' => 'error', 'message' => $api->getErrorMessage(), 'label' => $api->getErrorLabel()];
}
return $this->display('/home/field/json', ['api' => $api, 'project' => $api->project]);
}
}