コード例 #1
0
 public function actionCreate()
 {
     if (!self::can('domain/create')) {
         if (!self::can("domain/read")) {
             return $this->goHome();
         } else {
             Yii::$app->getSession()->addFlash('warning', Yii::t('topology', 'You are not allowed to add domains'));
             return $this->redirect(array('index'));
         }
     }
     $dom = new Domain();
     if ($dom->load($_POST)) {
         if ($dom->validate()) {
             if (!$dom->save()) {
                 foreach ($dom->getErrors() as $attribute => $error) {
                     Yii::$app->getSession()->addFlash("error", $error[0]);
                 }
             } else {
                 Yii::$app->getSession()->addFlash("success", Yii::t('topology', 'Domain {name} added successfully', ['name' => $dom->name]));
                 return $this->redirect(array('index'));
             }
         }
     }
     return $this->render('create', ['domain' => $dom]);
 }