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