private static function getConfig()
 {
     if (\Yii::$app->cache->exists('configuration') && !\Yii::$app->request->get('disableConfigCache')) {
         return \Yii::$app->cache->get('configuration');
     }
     if (!self::$configuration) {
         self::$configuration = ArrayHelper::map(Configuration::find()->select(['key', 'value'])->asArray()->all(), 'key', 'value');
         \Yii::$app->cache->set('configuration', self::$configuration, 600);
     }
     return self::$configuration;
 }
Beispiel #2
0
 public function getCategories()
 {
     $categories = Category::find()->where(['deleted' => 0])->all();
     return ArrayHelper::map($categories, 'id', 'title');
 }
Beispiel #3
0
<?php

use backend\helpers\ArrayHelper;
use backend\models\Category;
use backend\models\News;
use kartik\form\ActiveForm;
use kartik\select2\Select2;
use yii\web\JsExpression;
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-theme-form', 'options' => ['data-pjax' => true]]);
echo $form->field($model, 'name'), $form->field($model, 'categories')->widget(Select2::className(), ['options' => ['multiple' => true], 'data' => !$model->isNew ? ArrayHelper::map(Category::find()->select('id, title')->where(['deleted' => 0])->andWhere(['in', 'id', $model->categories])->asArray()->all(), 'id', 'title') : [], 'pluginOptions' => ['ajax' => ['url' => '/categories/get-list', 'data-type' => 'json', 'data' => new JsExpression("function(params){ return {q:params.term} }")]]]), $form->field($model, 'articles')->widget(Select2::className(), ['options' => ['multiple' => true], 'data' => !$model->isNew ? ArrayHelper::map(News::find()->select('id, title')->where(['deleted' => 0])->andWhere(['in', 'id', $model->articles])->asArray()->all(), 'id', 'title') : [], 'pluginOptions' => ['ajax' => ['url' => '/news/get-list', 'data-type' => 'json', 'data' => new JsExpression('function(params){ var data = {q:params.term}, categories = $("#mainthemeform-categories").val(); if(categories !== null && categories.length > 0){ data.excludedCategories = categories;} return data; }')]]]), $form->field($model, 'color')->dropDownList($model->getColors()), $form->field($model, 'titleWords', ['inputOptions' => ['format' => 'number']]), $form->field($model, 'textWords', ['inputOptions' => ['format' => 'number']]), $form->field($model, 'enabled')->checkbox([], false), \yii\bootstrap\Html::tag('div', \yii\bootstrap\Html::button('Сохранить', ['class' => 'btn btn-success btn-lg', 'type' => 'submit']), ['class' => 'text-center']);
$form->end();
Beispiel #4
0
<div class="panel panel-default">
    <div class="panel-heading">
        <?php 
echo Html::button(FA::i('save') . Html::tag('small', 'Сохранить'), ['class' => 'btn btn-app saveBtn']);
?>
    </div>
    <div class="panel-body">
        <div class="col-xs-10 col-xs-offset-1">
            <?php 
$form = ActiveForm::begin(['type' => ActiveForm::TYPE_HORIZONTAL, 'id' => 'edit-systemparams-form', 'options' => ['data-pjax' => true]]);
foreach ($model->items as $key => $item) {
    $defaultInputOptions = ['name' => 'ConfigurationFieldModel[' . $key . '][clearValue]', 'id' => 'configurationfieldmodel-' . $key . '-clearValue'];
    $field = $form->field($item, 'clearValue', ['inputOptions' => $defaultInputOptions + ['labelSpan' => 5]])->label($item->getKeyDescription());
    switch ($item->getFormat()) {
        case 'categories':
            $field->widget(\kartik\select2\Select2::className(), ['options' => array_merge($defaultInputOptions, ['multiple' => true]), 'data' => $item->clearValue ? ArrayHelper::map(Category::find()->select('id, title')->where(['deleted' => 0])->andWhere(['in', 'id', $item->clearValue])->asArray()->all(), 'id', 'title') : [], 'pluginOptions' => ['ajax' => ['url' => '/categories/get-list', 'data-type' => 'json', 'data' => new JsExpression("function(params){ return {q:params.term} }")]]]);
            break;
        case 'textarea':
            $field->textarea();
            break;
        case 'number':
            $field->inputOptions = array_merge($defaultInputOptions, ['type' => 'number']);
            break;
    }
    echo $field, $form->field($item, 'id', ['options' => ['style' => 'display: none'], 'inputOptions' => ['name' => 'ConfigurationFieldModel[' . $key . '][id]']])->label(false);
}
echo Html::tag('div', Html::button('Сохранить', ['type' => 'submit', 'class' => 'btn btn-success']), ['class' => 'text-center']);
$form->end();
?>
        </div>
    </div>