forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateController.php
More file actions
executable file
·58 lines (37 loc) · 1.24 KB
/
Copy pathTemplateController.php
File metadata and controls
executable file
·58 lines (37 loc) · 1.24 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
<?php
namespace app\controllers\home;
use Yii;
use yii\web\Response;
use app\models\Api;
use app\models\Project;
use app\models\template\UpdateTemplate;
/**
* Site controller
*/
class TemplateController extends PublicController
{
/**
* 更新模板
* @param $id
* @return array|string
*/
public function actionForm($project_id)
{
$request = Yii::$app->request;
$project = Project::findModel(['encode_id' => $project_id]);
$template = UpdateTemplate::findModel(['project_id' => $project->id]);
$api = Api::findModel();
if($request->isPost){
Yii::$app->response->format = Response::FORMAT_JSON;
if(!$template->load($request->post())){
return ['status' => 'error', 'message' => '加载数据失败'];
}
$template->project_id = $project->id;
if ($template->store()) {
return ['status' => 'success', 'message' => '保存成功'];
}
return ['status' => 'error', 'message' => $template->getErrorMessage(), 'label' => $template->getErrorLabel()];
}
return $this->display('form', ['project' => $project, 'template' => $template, 'api' => $api]);
}
}