/** * @inheritdoc */ public function beforeSave($insert) { $attributes = array_keys($this->getAttributes()); if (property_exists($this, 'category_id')) { $this->isCategory(); } // Upload image if (in_array('image', $attributes)) { $this->image = \yii\web\UploadedFile::getInstance($this, 'image'); $ext = FileHelper::getExtention($this->image); if (!empty($ext)) { $fileDir = Yii::$app->controller->module->id . '/' . date('Y/m/d/'); $fileName = LetHelper::string_to_url($this->title) . '.' . $ext; $folder = Yii::$app->params['uploadPath'] . '/' . Yii::$app->params['uploadDir'] . '/' . $fileDir; FileHelper::createDirectory($folder); $this->image->saveAs($folder . $fileName); $this->image = $fileDir . $fileName; } } // creator, editor and time $now = date('Y-m-d H:i:s', time()); if (in_array('update_time', $attributes)) { $this->update_time = $now; } if (in_array('editor', $attributes)) { $this->editor = Yii::$app->user->id; } if ($this->isNewRecord) { if (in_array('creator', $attributes)) { $this->creator = Yii::$app->user->id; } if (in_array('create_time', $attributes)) { $this->create_time = $now; } } return parent::beforeSave($insert); }
public function actionIndex() { $string = 'Cộng hòa $##@ xã hội chủ nghĩa Việt Nam'; echo \app\components\LetHelper::string_to_url($string); }