public static function getParameterValue($parametername = "")
 {
     $para = Parameter::findOne(['parametername' => $parametername]);
     if (isset($para)) {
         return $para->value;
     } else {
         return null;
     }
 }
 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var $module Module */
     if ($app->hasModule('configmanager') && ($module = $app->getModule('configmanager')) instanceof Module) {
         $this->_modelMap = array_merge($this->_modelMap, $module->modelMap);
         foreach ($this->_modelMap as $name => $definition) {
             $class = "chd7well\\configmanager\\models\\" . $name;
             \Yii::$container->set($class, $definition);
             $modelName = is_array($definition) ? $definition['class'] : $definition;
             $module->modelMap[$name] = $modelName;
             if (in_array($name, ['Configmanager'])) {
                 \Yii::$container->set($name . 'Query', function () use($modelName) {
                     return $modelName::find();
                 });
             }
         }
     }
     $app->get('i18n')->translations['configmanager*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages'];
     //Load parameters from database
     $parameters = Parameter::find()->where(['bootstrap' => '1'])->all();
     //only on bootstrap are necessary
     foreach ($parameters as $para) {
         $this->setParameter($app, $para->parametername, $para->value);
     }
     $is_config_set = Parameter::findOne(['parametername' => 'chd7well/configmanager/config_set']);
     $is_user_config_set = Parameter::findOne(['parametername' => 'chd7well/configmanager/user_parameter']);
     if (get_class(\Yii::$app) === 'yii\\web\\Application') {
         if (isset($app->params['chd7well/configmanager/config_set']) && isset($app->params['chd7well/configmanager/user_parameter']) && $app->params['chd7well/configmanager/config_set'] == 1 && $app->params['chd7well/configmanager/user_parameter'] == 1 && isset(\Yii::$app->user->id)) {
             $configuser = ConfigUser::findOne(['user_ID' => \Yii::$app->user->id]);
             if (isset($configuser)) {
                 $config = Config::findOne(['ID' => $configuser->config_ID]);
                 $parent_parameters = ConfigParameter::find()->where(['config_ID' => $config->parent_ID])->all();
                 $user_parameters = ConfigParameter::find()->where(['config_ID' => $config->ID])->all();
                 foreach ($parent_parameters as $para) {
                     $this->setParameter($app, $para->parameter->parametername, $para->value);
                 }
                 foreach ($user_parameters as $para) {
                     $this->setParameter($app, $para->parameter->parametername, $para->value);
                 }
             }
         }
     }
 }
<?php

use yii\helpers\ArrayHelper;
use chd7well\configmanager\models\Parameter;
/*
 * This file is part of the chd7well project.
 *
 * (c)2015 chd7well project <http://github.com/chd7well>
 *
 * For the full copyright and license information, please view the LICENSE.md
 * file that was distributed with this source code.
 */
/**
 * @var yii\widgets\ActiveForm    $form
 * @var chd7well\user\models\Config $config
 */
?>

<?php 
echo $form->field($config, 'parameter_ID')->dropDownList(ArrayHelper::map(Parameter::find()->all(), 'ID', 'parametername'));
echo $form->field($config, 'value')->textInput();
?>

 /**
  * @return \yii\db\ActiveQuery
  */
 public function getParameter()
 {
     return $this->hasOne(Parameter::className(), ['ID' => 'parameter_ID']);
 }
Example #5
0
 * For the full copyright and license information, please view the LICENSE.md
 * file that was distributed with this source code.
 */
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use chd7well\configmanager\models\Parameter;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var chd7well\user\models\UserSearch $searchModel
 */
$this->title = Yii::t('configmanager', 'Manage Parameters');
$this->params['breadcrumbs'][] = $this->title;
//echo \Yii::$app->params['chd'] . '<br>';
echo Parameter::getParameterValue('chd');
?>
<h1><?php 
echo Html::encode($this->title);
?>
 <?php 
echo Html::a(Yii::t('configmanager', 'Create a parameter'), ['create'], ['class' => 'btn btn-success']);
?>
</h1>


<?php 
Pjax::begin();
?>

<?php 
 /**
  * Finds the Parameter model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Config the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Parameter::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }