public function beforeValidate() { if (parent::beforeValidate()) { $this->title_format = CommonUtility::getTitleFormatValue($this->title_format); $uploadedFile = CommonUtility::uploadFile('Fragment2Data[title_pic]'); if ($uploadedFile != null) { $this->title_pic = $uploadedFile['url'] . $uploadedFile['new_name']; } return true; } return false; }
public function saveContent($model) { $model->removeSpecialAtt(); $model->user_id = 1; $model->user_name = 'admin'; $model->publish_time = TTimeHelper::getCurrentTime(); $model->modify_time = TTimeHelper::getCurrentTime(); $model->title_format = CommonUtility::getTitleFormatValue($model->title_format); $model->flag = CommonUtility::getFlagValue($model->flag); $uploadedFile = CommonUtility::uploadFile('Content[title_pic]'); if ($uploadedFile != null) { $model->title_pic = $uploadedFile['url'] . $uploadedFile['new_name']; } if ($model->title_pic == null || empty($model->title_pic)) { $model->is_pic = 0; } else { $model->is_pic = 1; } if ($model->views == null) { $model->views = 0; } if ($model->commonts == null) { $model->commonts = 0; } if ($model->summary == null || empty($model->summary)) { $content = strip_tags($model->content); $pattern = '/\\s/'; //去除空白 $content = preg_replace($pattern, '', $content); $model->summary = TStringHelper::subStr($content, 250); } $command = LuLu::createCommand(); if ($model->isNewRecord) { $command->insert($this->currentTableName, $model); } else { $command->update($this->currentTableName, $model, ['id' => $model['id']]); } $command->execute(); }
public function beforeValidate() { if (parent::beforeValidate()) { $this->title_format = CommonUtility::getTitleFormatValue($this->title_format); $uploadedFile = CommonUtility::uploadFile('Page[title_pic]'); if ($uploadedFile != null) { $this->title_pic = $uploadedFile['url'] . $uploadedFile['new_name']; } if (!is_int($this->sort_num)) { $this->sort_num = 0; } $this->publish_time = TTimeHelper::getCurrentTime(); $this->modify_time = TTimeHelper::getCurrentTime(); if ($this->summary == null || empty($this->summary)) { $body = strip_tags($this->body); $pattern = '/\\s/'; //去除空白 $body = preg_replace($pattern, '', $body); $this->summary = TStringHelper::subStr($body, 250); } return true; } return false; }