public function actionAdd()
 {
     $name = $_POST['name'];
     $description = $_POST['description'];
     $districtName = $_POST['districtName'];
     $addr = $_POST['address'];
     $postCode = $_POST['postCode'];
     $address = new Address();
     $address->address = $addr;
     $address->post_code = $postCode;
     $address->save();
     $district = District::find()->where(['name' => $districtName])->one();
     if ($district == NULL) {
         $district = new District();
         $district->name = $districtName;
         $district->save();
     }
     $department = new Department();
     $department->name = $name;
     $department->description = $description;
     $department->district_id = $district->id;
     $department->address_id = $address->id;
     $department->save();
     $this->redirect(['/department/list']);
 }
Example #2
0
 public function getAddress()
 {
     return $this->hasOne(Address::className(), ['id' => 'address_id']);
 }