/** * update settings */ public static function updateSetting() { $s = [['key' => 'title', 'value' => 'Yii2 Skeleton', 'title' => 'Title', 'description' => 'Homepage title', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2 Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'keywords', 'value' => 'Yii2, Skeleton', 'title' => 'Keywords', 'description' => 'Homepage keywords', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2, Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'description', 'value' => 'Skeleton for Yii Framework', 'title' => 'Description', 'description' => 'Homepage description', 'group' => 'General', 'type' => 'textInput', 'data' => '[]', 'default' => 'Skeleton for Yii Framework', 'rules' => json_encode(['required' => []])], ['key' => 'language', 'value' => 'en-US', 'title' => 'Language', 'description' => 'Site language', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{LOCALE}', 'default' => 'en-US', 'rules' => json_encode(['required' => []])], ['key' => 'timezone', 'value' => 'Asia/Ho_Chi_Minh', 'title' => 'Timezone', 'description' => 'Server Timezone', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{TIMEZONE}', 'default' => 'Asia/Ho_Chi_Minh', 'rules' => json_encode(['required' => []])], ['key' => 'maxNameChange', 'value' => '1', 'title' => 'Max Name Change', 'description' => 'Max name change allowed', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '1', 'rules' => json_encode(['required' => [], 'number' => ['min' => -1]])], ['key' => 'tokenExpiryTime', 'value' => '3600', 'title' => 'Token Expiry Time', 'description' => 'Expiration time in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '3600', 'rules' => json_encode(['required' => [], 'number' => ['min' => 3600]])], ['key' => 'rememberMeDuration', 'value' => '2592000', 'title' => 'Remember Me Duration', 'description' => 'Customize the duration of the Remember Me in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '2592000', 'rules' => json_encode(['required' => [], 'number' => ['min' => 86400]])], ['key' => 'blogTitle', 'value' => 'My Blog', 'title' => 'Title', 'description' => 'Blog page title', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'My Blog', 'rules' => json_encode(['required' => []])], ['key' => 'blogDesc', 'value' => 'Welcome to my world.', 'title' => 'Description', 'description' => 'Blog page description', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'Welcome to my world.', 'rules' => json_encode(['required' => []])], ['key' => 'blogKeywords', 'value' => 'blog, my blog', 'title' => 'Keywords', 'description' => 'Blog page keywords', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => 'blog, my blog', 'rules' => json_encode(['required' => []])], ['key' => 'blogThumbnail', 'value' => '', 'title' => 'Thumbnail Image', 'description' => 'Blog page thumbnail', 'group' => 'Blog', 'type' => 'textInput', 'data' => json_encode(Core::getYesNoOption()), 'default' => '', 'rules' => json_encode(['url' => []])], ['key' => 'outgoingMail', 'value' => '*****@*****.**', 'title' => 'Outgoing Mail', 'description' => 'Outgoing email address', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['required' => [], 'email' => []])], ['key' => 'mailProtocol', 'value' => 'php', 'title' => 'Mail Protocol', 'description' => 'Outgoing email protocol', 'group' => 'Mail', 'type' => 'dropDownList', 'data' => json_encode(['php' => 'php', 'smtp' => 'smtp']), 'default' => 'php', 'rules' => json_encode(['required' => []])], ['key' => 'smtpHost', 'value' => '', 'title' => 'SMTP Host', 'description' => 'SMTP host', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpUsername', 'value' => '', 'title' => 'SMTP Username', 'description' => 'SMTP username', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpPassword', 'value' => '', 'title' => 'SMTP Password', 'description' => 'SMTP password', 'group' => 'Mail', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'smtpPort', 'value' => '', 'title' => 'SMTP Port', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '25', 'rules' => json_encode(['safe' => [], 'number' => []])], ['key' => 'smtpEncryption', 'value' => '', 'title' => 'SMTP Encryption', 'description' => 'SMTP Encryption', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => 'ssl', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'fbPageUrl', 'value' => '', 'title' => 'Facebook Page URL', 'description' => 'Facebook Page URL', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'url' => []])], ['key' => 'fbAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'fbAdmins', 'value' => '', 'title' => 'Facebook Admins', 'description' => 'Facebook Admins ID', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'gpPageUrl', 'value' => '', 'title' => 'Google+ Page URL', 'description' => 'Google+ Page URL', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'url' => []])], ['key' => 'twitterSite', 'value' => '', 'title' => 'Twitter Card Site', 'description' => '@username for the website used', 'group' => 'Social', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'reCaptchaKey', 'value' => '', 'title' => 'reCaptcha Site Key', 'description' => 'reCaptcha Site Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'reCaptchaSecret', 'value' => '', 'title' => 'reCaptcha Secret', 'description' => 'reCaptcha Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'facebookAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'facebookAppSecret', 'value' => '', 'title' => 'Facebook App Secret', 'description' => 'Facebook App Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleClientId', 'value' => '', 'title' => 'Google Client ID', 'description' => 'Google Client ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleClientSecret', 'value' => '', 'title' => 'Google Client Secret', 'description' => 'Google Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'flickrClientKey', 'value' => '', 'title' => 'Flickr Client Key', 'description' => 'Flickr Client Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'flickrClientSecret', 'value' => '', 'title' => 'Flickr Client Secret', 'description' => 'Flickr Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'androidThemeColor', 'value' => '#3c8dbc', 'title' => 'Android Theme Color', 'description' => 'Android theme color', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'msTileColor', 'value' => '#3c8dbc', 'title' => 'MS Tile Color', 'description' => 'Background color for a live tile', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'safariMaskColor', 'value' => '#3c8dbc', 'title' => 'Safari Mask Color', 'description' => 'Safari pinned tab color', 'group' => 'Theme', 'type' => 'textInput', 'data' => '[]', 'default' => '#3c8dbc', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleCustomSearch', 'value' => '', 'title' => 'Google Custom Search', 'description' => 'CX code: 123456789012345678901:abcdefjh123', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'googleAnalytics', 'value' => '', 'title' => 'Google Analytics', 'description' => 'Tracking ID: UA-1111111-22', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'disqus', 'value' => '', 'title' => 'Disqus', 'description' => 'Disqus shortname', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'zopim', 'value' => '', 'title' => 'Zopim Chat', 'description' => 'Zopim ID: 5d8f1e3c8f77c45608ada76d51256aad', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'addthis', 'value' => '', 'title' => 'Addthis', 'description' => 'Addthis ID: ra-123a1234567890b1', 'group' => 'Enhancements', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'headJs', 'value' => '', 'title' => 'Header JS', 'description' => 'Header Javascript', 'group' => 'Enhancements', 'type' => 'textarea', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'adsense', 'value' => '', 'title' => 'Google Adsense', 'description' => 'Client ID: ca-pub-1234567890123456', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzTracking', 'value' => '', 'title' => 'Amazon Tracking ID', 'description' => 'Tracking ID: yourname-11', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzAds', 'value' => '', 'title' => 'Amazon Native Ads', 'description' => 'Ad Instance ID: 12abc1ab-ab12-1234-a123-1abcd123456a', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'amzSearchAds', 'value' => '', 'title' => 'Amazon Search Ads', 'description' => 'Link ID: 12abc1ab-ab12-1234-a123-1abcd123456a', 'group' => 'Ads', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => [], 'string' => []])], ['key' => 'languageUrlCode', 'value' => '0', 'title' => 'Language URL', 'description' => 'Include language code in URL', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])], ['key' => 'debug', 'value' => '0', 'title' => 'Debug Mode', 'description' => 'Turn debug mode ON/OFF', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])]]; /* delete old settings */ $settings = Setting::find()->all(); foreach ($settings as $setting) { if (!in_array($setting->key, array_column($s, 'key'))) { $setting->delete(); } } /* sync */ foreach ($s as $i => $setting) { $conf = Setting::findOne($setting['key']); if (!$conf) { $conf = new Setting(); $conf->key = $setting['key']; $conf->value = $setting['value']; } $conf->title = $setting['title']; $conf->description = $setting['description']; $conf->group = $setting['group']; $conf->type = $setting['type']; $conf->data = $setting['data']; $conf->default = $setting['default']; $conf->rules = $setting['rules']; $conf->key_order = $i; $conf->save(); } }
/** * Creates a new Setting model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Setting(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Lists all Post models. * @return mixed */ public function actionIndex() { $model = new Setting(); $dataProvider = new ActiveDataProvider(['query' => Setting::find()]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]); }
/** * Creates a new Setting model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Setting(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', 'Well done! successfully to save data! '); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Setting model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $Setting = new Setting(); $Setting_en = new Setting_en(); $Setting_ru = new Setting_ru(); if ($Setting->load(Yii::$app->request->post()) && $Setting_en->load(Yii::$app->request->post()) && $Setting_ru->load(Yii::$app->request->post()) && $Setting->save()) { $Setting_en->setting_id = $Setting->id; $Setting_ru->setting_id = $Setting->id; $Setting_en->save(); $Setting_ru->save(); return $this->redirect(['view', 'id' => $Setting->id]); } else { return $this->render('create', ['Setting' => $Setting, 'Setting_en' => $Setting_en, 'Setting_ru' => $Setting_ru]); } }
public function actionInit() { $model = new User(); $model->username = '******'; $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG'; $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC'; $model->email = '*****@*****.**'; $model->phone = '6281575068530'; $model->role = User::ROLE_ADMIN; $model->status = User::STATUS_ACTIVE; if ($model->save()) { echo "\r\n success insert user, with username:admin and password:123456 \r\n"; } else { echo json_encode($model->getErrors()); } $model = new Member(); $model->username = '******'; $model->auth_key = 'OocVKRx-iludROmUFYj4HmxNeC8v0-FG'; $model->password_hash = '$2y$13$0d3FeUDYGSyZft.3I77hV.E357FsqqAJFqaWPstWODMbdlSvxV2gC'; $model->email = '*****@*****.**'; $model->phone = '6281575068530'; $model->role = Member::ROLE_ADMIN; $model->status = Member::STATUS_ACTIVE; if ($model->save()) { echo "\r\n success insert member, with username:admin and password:123456 \r\n"; } else { echo json_encode($model->getErrors()); } $setting = new Setting(); $setting->emailAdmin = '*****@*****.**'; $setting->emailSupport = '*****@*****.**'; $setting->emailOrder = '*****@*****.**'; $setting->facebook = 'https://www.facebook.com/sintret'; $setting->instagram = 'https://instagram.com/andyfitria/'; $setting->google = 'https://google.com/sintret/'; if ($setting->save()) { echo "\r\n success insert advanced settings... \r\n"; } else { echo json_encode($setting->getErrors()); } }
/** * insert settings */ protected function insertSettings() { $s = [['key' => 'languageUrlCode', 'value' => '0', 'title' => 'Language URL', 'description' => 'Include language code in URL', 'group' => 'SEO', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])]]; foreach ($s as $i => $setting) { $conf = Setting::findOne($setting['key']); if (!$conf) { $conf = new Setting(); $conf->key = $setting['key']; $conf->value = $setting['value']; } $conf->title = $setting['title']; $conf->description = $setting['description']; $conf->group = $setting['group']; $conf->type = $setting['type']; $conf->data = $setting['data']; $conf->default = $setting['default']; $conf->rules = $setting['rules']; $conf->key_order = $i; $conf->save(); } //return $this->redirect(['index']); }
protected function insertSettings() { $s = [['key' => 'language', 'value' => 'en-US', 'title' => 'Language', 'description' => 'Site language', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{LOCALE}', 'default' => 'en-US', 'rules' => json_encode(['required' => []])], ['key' => 'timezone', 'value' => 'Asia/Ho_Chi_Minh', 'title' => 'Timezone', 'description' => 'Server Timezone', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{TIMEZONE}', 'default' => 'Asia/Ho_Chi_Minh', 'rules' => json_encode(['required' => []])], ['key' => 'maxNameChange', 'value' => '1', 'title' => 'Max Name Change', 'description' => 'Max name change allowed', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '1', 'rules' => json_encode(['required' => [], 'number' => ['min' => -1]])], ['key' => 'tokenExpiryTime', 'value' => '3600', 'title' => 'Token Expiry Time', 'description' => 'Expiration time in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '3600', 'rules' => json_encode(['required' => [], 'number' => ['min' => 3600]])], ['key' => 'rememberMeDuration', 'value' => '2592000', 'title' => 'Remember Me Duration', 'description' => 'Customize the duration of the Remember Me in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '2592000', 'rules' => json_encode(['required' => [], 'number' => ['min' => 86400]])], ['key' => 'title', 'value' => 'Yii2 Skeleton', 'title' => 'Title', 'description' => 'Homepage title', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2 Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'keywords', 'value' => 'Yii2, Skeleton', 'title' => 'Keywords', 'description' => 'Homepage keywords', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2, Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'description', 'value' => 'Skeleton for Yii Framework', 'title' => 'Description', 'description' => 'Homepage description', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Skeleton for Yii Framework', 'rules' => json_encode(['required' => []])], ['key' => 'outgoingMail', 'value' => '*****@*****.**', 'title' => 'Outgoing Mail', 'description' => 'Outgoing email address', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['required' => [], 'email' => []])], ['key' => 'mailProtocol', 'value' => 'php', 'title' => 'Mail Protocol', 'description' => 'Outgoing email protocol', 'group' => 'Mail', 'type' => 'dropDownList', 'data' => json_encode(['php' => 'php', 'smtp' => 'smtp']), 'default' => 'php', 'rules' => json_encode(['required' => []])], ['key' => 'smtpHost', 'value' => '', 'title' => 'SMTP Host', 'description' => 'SMTP host', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpUsername', 'value' => '', 'title' => 'SMTP Username', 'description' => 'SMTP username', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpPassword', 'value' => '', 'title' => 'SMTP Password', 'description' => 'SMTP password', 'group' => 'Mail', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpPort', 'value' => '', 'title' => 'SMTP Port', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '25', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpEncryption', 'value' => '', 'title' => 'SMTP Encryption', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => 'ssl', 'rules' => json_encode(['safe' => []])], ['key' => 'reCaptchaKey', 'value' => '', 'title' => 'reCaptcha Site Key', 'description' => 'reCaptcha Site Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'reCaptchaSecret', 'value' => '', 'title' => 'reCaptcha Secret', 'description' => 'reCaptcha Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'facebookAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'facebookAppSecret', 'value' => '', 'title' => 'Facebook App Secret', 'description' => 'Facebook App Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'googleClientId', 'value' => '', 'title' => 'Google Client ID', 'description' => 'Google Client ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'googleClientSecret', 'value' => '', 'title' => 'Google Client Secret', 'description' => 'Google Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'flickrClientKey', 'value' => '', 'title' => 'Flickr Client Key', 'description' => 'Flickr Client Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'flickrClientSecret', 'value' => '', 'title' => 'Flickr Client Secret', 'description' => 'Flickr Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'debug', 'value' => '0', 'title' => 'Debug Mode', 'description' => 'Turn on debug mode', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => []])]]; foreach ($s as $i => $setting) { $conf = Setting::findOne($setting['key']); if (!$conf) { $conf = new Setting(); $conf->key = $setting['key']; $conf->value = $setting['value']; } $conf->title = $setting['title']; $conf->description = $setting['description']; $conf->group = $setting['group']; $conf->type = $setting['type']; $conf->data = $setting['data']; $conf->default = $setting['default']; $conf->rules = $setting['rules']; $conf->key_order = $i; $conf->save(); } //return $this->redirect(['index']); }
public function save() { $setting = Setting::findOne(['id' => $this->id]); if (empty($setting)) { $setting = new Setting(); $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('save:', YII_DEBUG); if ($setting->save()) { $this->_value_rules = $oldRules; $this->id = $setting->id; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('save error', YII_DEBUG); } } else { $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('update:', YII_DEBUG); if ($setting->update()) { $this->_value_rules = $oldRules; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('update error:' . print_r($setting, true), YII_DEBUG); } } return null; }