/** * Render the settings form. */ public function run() { /* @var $model \yii\db\ActiveRecord */ $model = new $this->modelClass(); if ($this->scenario) { $model->setScenario($this->scenario); } if ($model->load(Yii::$app->request->post()) && $model->validate()) { foreach ($model->toArray() as $key => $value) { Yii::$app->settings->set($key, $value, $model->formName()); } Yii::$app->getSession()->addFlash('success', Module::t('settings', 'Successfully saved settings on {section}', ['section' => $model->formName()])); } foreach ($model->attributes() as $key) { $model->{$key} = Yii::$app->settings->get($key, $model->formName()); } return $this->controller->render($this->viewName, ['model' => $model]); }
<?php /** * @link http://phe.me * @copyright Copyright (c) 2014 Pheme * @license MIT http://opensource.org/licenses/MIT */ use yii\helpers\Html; use pheme\settings\Module; /** * @var yii\web\View $this * @var pheme\settings\models\Setting $model */ $this->title = Module::t('settings', 'Create {modelClass}', ['modelClass' => Module::t('settings', 'Setting')]); $this->params['breadcrumbs'][] = ['label' => Module::t('settings', 'Settings'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="setting-create"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
/** * @inheritdoc */ public function attributeLabels() { return ['id' => Module::t('settings', 'ID'), 'type' => Module::t('settings', 'Type'), 'section' => Module::t('settings', 'Section'), 'key' => Module::t('settings', 'Key'), 'value' => Module::t('settings', 'Value'), 'active' => Module::t('settings', 'Active'), 'created' => Module::t('settings', 'Created'), 'modified' => Module::t('settings', 'Modified')]; }
<?php echo $form->field($model, 'section'); ?> <?php echo $form->field($model, 'key'); ?> <?php echo $form->field($model, 'value'); ?> <?php echo $form->field($model, 'active')->checkbox(); ?> <div class="form-group"> <?php echo Html::submitButton(Module::t('settings', 'Search'), ['class' => 'btn btn-primary']); ?> <?php echo Html::resetButton(Module::t('settings', 'Reset'), ['class' => 'btn btn-default']); ?> </div> <?php ActiveForm::end(); ?> </div>
<?php /** * @link http://phe.me * @copyright Copyright (c) 2014 Pheme * @license MIT http://opensource.org/licenses/MIT */ use yii\helpers\Html; use pheme\settings\Module; /** * @var yii\web\View $this * @var pheme\settings\models\Setting $model */ $this->title = Module::t('settings', 'Update {modelClass}: ', ['modelClass' => Module::t('settings', 'Setting')]) . ' ' . $model->section . '.' . $model->key; $this->params['breadcrumbs'][] = ['label' => Module::t('settings', 'Settings'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = Module::t('settings', 'Update'); ?> <div class="setting-update"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo $this->render('_form', ['model' => $model]); ?> </div>
echo $form->field($model, 'section')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'key')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'value')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'active')->checkbox(['value' => 1]); ?> <?php echo $form->field($model, 'type')->dropDownList(['string' => 'string', 'integer' => 'integer', 'boolean' => 'boolean', 'float' => 'float', 'array' => 'array', 'object' => 'object', 'null' => 'null'])->hint(Module::t('settings', 'Change at your own risk')); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? Module::t('settings', 'Create') : Module::t('settings', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
* @var yii\data\ActiveDataProvider $dataProvider */ $this->title = Module::t('settings', 'Settings'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="setting-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php //echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Module::t('settings', 'Create {modelClass}', ['modelClass' => Module::t('settings', 'Setting')]), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php Pjax::begin(); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => ['id', ['attribute' => 'section', 'filter' => ArrayHelper::map(Setting::find()->select('section')->distinct()->where(['<>', 'section', ''])->all(), 'section', 'section')], 'key', 'value:ntext', ['class' => '\\pheme\\grid\\ToggleColumn', 'attribute' => 'active', 'filter' => [1 => Yii::t('yii', 'Yes'), 0 => Yii::t('yii', 'No')]], ['class' => 'yii\\grid\\ActionColumn']]]); ?> <?php Pjax::end(); ?> </div>
use pheme\settings\Module; /** * @var yii\web\View $this * @var pheme\settings\models\Setting $model */ $this->title = $model->section . '.' . $model->key; $this->params['breadcrumbs'][] = ['label' => Module::t('settings', 'Settings'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="setting-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Module::t('settings', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Module::t('settings', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Module::t('settings', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'type', 'section', 'active:boolean', 'key', 'value:ntext', 'created:datetime', 'modified:datetime']]); ?> </div>