forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateTemplate.php
More file actions
54 lines (43 loc) · 1.16 KB
/
Copy pathUpdateTemplate.php
File metadata and controls
54 lines (43 loc) · 1.16 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
<?php
namespace app\models\template;
use Yii;
use app\models\Template;
class UpdateTemplate extends Template
{
/**
* 验证规则
*/
public function rules()
{
return [
[['id'], 'required'],
[['header_fields', 'request_fields', 'response_fields'], 'string'],
];
}
/**
* 保存模板
* @return bool
*/
public function store()
{
if(!$this->validate()){
return false;
}
// 开启事务
$transaction = Yii::$app->db->beginTransaction();
$template = &$this;
$template->header_fields = $this->header_fields;
$template->request_fields = $this->request_fields;
$template->response_fields = $this->response_fields;
$template->status = $template::ACTIVE_STATUS;
$template->updater_id = Yii::$app->user->identity->id;
if(!$template->save()){
$this->addError($template->getErrorLabel(), $template->getErrorMessage());
$transaction->rollBack();
return false;
}
// 事务提交
$transaction->commit();
return true;
}
}