public function actionCreate($fraid) { $model = new Fragment2Data(); $model->fragment_id = $fraid; $model->publish_time = TTimeHelper::getCurrentTime(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index', 'fraid' => $fraid]); } else { $locals = []; $locals['model'] = $model; $locals['currentFragment'] = Fragment::findOne($fraid); return $this->render('create', $locals); } }
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 = CommonContent::getFormatValue($model->title_format); $model->flag = CommonContent::getFlatValue($model->flag); $db = Yii::$app->db; $command = $db->createCommand(); if ($model->isNewRecord) { $command->insert($this->currentTableName, $model); } else { $command->update($this->currentTableName, $model, ['id' => $model['id']]); } $command->execute(); }
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; }
public function beforeValidate() { if (parent::beforeValidate()) { if ($this->hasAttribute('sort_num')) { if ($this->sort_num == null || $this->sort_num == '') { $this->sort_num = 0; } } if ($this->hasAttribute('publish_time')) { if ($this->publish_time == null || $this->publish_time == '') { $this->publish_time = TTimeHelper::getCurrentTime(); } } if ($this->hasAttribute('modify_time')) { if ($this->modify_time == null || $this->modify_time == '') { $this->modify_time = TTimeHelper::getCurrentTime(); } } return true; } return false; }