| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace common\models\forms;
- use common\components\Model;
- use common\helpers\Form;
- use common\models\SmsTemplate;
- /**
- * Login form
- */
- class SmsTemplateForm extends Model
- {
- public $id;
- public $content;
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'content'], 'trim'],
- [['id', 'content'], 'required'],
- ];
- }
- /**
- * 指定校验场景
- * @return array
- */
- public function scenarios()
- {
- $parentScenarios = parent::scenarios();
- $customScenarios = [
- 'edit' => ['content']
- ];
- return array_merge($parentScenarios, $customScenarios);
- }
- public function attributeLabels()
- {
- return [
- 'content' => '模板内容',
- ];
- }
- /**
- * 编辑短信模板
- * @return null|static
- */
- public function edit(){
- if(!$this->validate()){
- return null;
- }
- $model = SmsTemplate::findOne($this->id);
- $model->CONTENT = $this->content;
- if(!$model->save()){
- $this->addError('edit', Form::formatErrorsForApi($model->getErrors()));
- return null;
- }
- return $model;
- }
- }
|