コード例 #1
0
 /** @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);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * 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 = Config::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }