コード例 #1
0
 /**
  * Render option page for specific group of option.
  * It will use group file if exist.
  *
  * @param string $id group name
  *
  * @return string|\yii\web\Response
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionGroup($id)
 {
     $model = Option::find()->where(['option_group' => $id])->indexBy('option_name')->all();
     if ($options = Yii::$app->request->post('Option')) {
         foreach ($options as $option_name => $option) {
             Option::up($option_name, $option['option_value']);
         }
         Yii::$app->getSession()->setFlash('success', Yii::t('content', 'Settings successfully saved.'));
         return $this->refresh();
     }
     if ($model) {
         if (is_file($viewFile = $this->getViewPath() . '/' . strtolower($id) . '.php')) {
             return $this->render(strtolower($id), ['model' => (object) $model, 'group' => $id]);
         } else {
             return $this->redirect('index');
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }