Example #1
0
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $domain = preg_split("/\r\n/isU", trim($this->domain_txt));
     $site_id = $this->getPrimaryKey();
     $domains = Domain::find()->where(['site_id' => $site_id])->all();
     foreach ($domain as $key => $dm) {
         $dm = trim($dm);
         if (empty($dm)) {
             continue;
         }
         $domain_model = $this->findModelByDomain($domains, $dm);
         if (!isset($domain_model)) {
             $domain_model = new Domain();
         }
         if ($key === 0) {
             $domain_model->main = 1;
         } else {
             $domain_model->main = 0;
         }
         $domain_model->domain = $dm;
         $domain_model->site_id = $this->id;
         $domain_model->save();
     }
 }
Example #2
0
 /**
  * Creates a new Domain model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Domain();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'dealerItems' => $this->getDealerItems()]);
     }
 }