public function init() { parent::init(); $extJsSrcDir = Yii::getAlias($this->extJsDir); $extJsSrcExtendDir = Yii::getAlias($this->extJsExtendDir); $dstDir = Yii::getAlias($this->dstPath); $extJsDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs'; $extJsExtendDstDir = $dstDir . DIRECTORY_SEPARATOR . 'extjs-extend'; if (!is_dir($dstDir)) { if (!is_dir($dstDir)) { FileHelper::createDirectory($dstDir); } } if (!is_dir($extJsDstDir)) { symlink($extJsSrcDir, $extJsDstDir); } if (!is_dir($extJsExtendDstDir)) { symlink($extJsSrcExtendDir, $extJsExtendDstDir); } $data = DpConfig::find()->all(); $config = []; foreach ($data as $item) { $config[$item['name']] = $item['value']; } $this->config = $config; $this->identity = Yii::$app->user->identity; }
/** * 保存数据 * * @return array */ public function actionSave() { $config = \Yii::$app->request->post('config'); if ($config) { foreach ($config as $name => $value) { DpConfig::replaceByName($name, $value, 1); } // logo上传 $uploadModel = new ConfigUploadForm(); $uploadModel->imageFile = UploadedFile::getInstance($uploadModel, 'logo_file'); if ($uploadModel->upload()) { DpConfig::replaceByName('website.logo', $uploadModel->savePath, 1); } elseif (!$this->getConfig('website.logo')) { foreach ($uploadModel->getErrors() as $error) { foreach ($error as $message) { return $this->renderError($message); } } } // 二维码上传 $uploadModel = new ConfigUploadForm(); $uploadModel->imageFile = UploadedFile::getInstance($uploadModel, 'qr_file'); if ($uploadModel->upload()) { DpConfig::replaceByName('website.qr', $uploadModel->savePath, 1); } elseif (!$this->getConfig('website.qr')) { foreach ($uploadModel->getErrors() as $error) { foreach ($error as $message) { return $this->renderError($message); } } } return $this->renderSuccess('保存成功'); } else { return $this->renderError('数据不能为空'); } }
public function init() { parent::init(); // 默认配置 $this->extJs['path'] = ArrayHelper::getValue($this->extJs, 'path', '/dp/extjs'); $this->extJs['extendPath'] = ArrayHelper::getValue($this->extJs, 'extendPath', '/dp/extjs-extend'); $this->extJs['appJsPath'] = ArrayHelper::getValue($this->extJs, 'appJsPath', $this->extJs['extendPath'] . '/app.js'); $this->extJs['bootstrapJsPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapJsPath', $this->extJs['extendPath'] . '/bootstrap.js'); $this->extJs['bootstrapJsonPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapJsonPath', $this->extJs['extendPath'] . '/bootstrap.json'); $this->extJs['bootstrapCssPath'] = ArrayHelper::getValue($this->extJs, 'bootstrapCssPath', $this->extJs['path'] . '/packages/ext-theme-crisp/build/resources/ext-theme-crisp-all.css'); // js路径 $extJsSrcDir = Yii::getAlias($this->srcExtJsDir); $extJsSrcExtendDir = Yii::getAlias($this->srcExtJsExtendDir); $extJsDstDir = Yii::getAlias('@app/web/' . $this->extJs['path']); $extJsExtendDstDir = Yii::getAlias('@app/web/' . $this->extJs['extendPath']); // 创建符号连接所需的目录 $extJsDstUpDir = dirname($extJsDstDir); if (!is_dir($extJsDstUpDir)) { @rmdir($extJsDstUpDir); if (!is_dir($extJsDstUpDir)) { FileHelper::createDirectory($extJsDstUpDir); } } $extJsExtendDstUpDir = dirname($extJsExtendDstDir); if (!is_dir($extJsExtendDstUpDir)) { @rmdir($extJsExtendDstUpDir); if (!is_dir($extJsExtendDstUpDir)) { FileHelper::createDirectory($extJsExtendDstUpDir); } } // js目录创建符号连接 if (!is_dir($extJsDstDir)) { symlink($extJsSrcDir, $extJsDstDir); } if (!is_dir($extJsExtendDstDir)) { symlink($extJsSrcExtendDir, $extJsExtendDstDir); } $data = DpConfig::find()->all(); $config = []; foreach ($data as $item) { $config[$item['name']] = $item['value']; } $this->config = $config; $this->identity = Yii::$app->user->identity; }