Ejemplo n.º 1
0
 /**
  * Creates a new Sitename model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Sitename();
     if ($model->load(Yii::$app->request->post())) {
         $a = $model->sitecode;
         $b = $model->sitename;
         $connection = \Yii::$app->db;
         $sql = $connection->createCommand('SELECT  sitecode  FROM Sitename WHERE sitecode = "' . $a . '"')->queryAll();
         $sql2 = $connection->createCommand('SELECT  sitename  FROM Sitename WHERE sitename = "' . $b . '"')->queryAll();
         if ($sql != null || $sql2 != null) {
             echo "<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\t\t\twindow.alert('Sitecode or Sitename has already existing')\n\t\t\t\t\t\twindow.location.href='index.php?r=project%2Findex';\n\t\t\t\t\t\t</SCRIPT>";
         } else {
             $model->save();
             return $this->redirect(['project/index']);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
     //echo "<a href='index.php?r=project%2Findex'> Go Back</a>";
 }