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']);
 }
예제 #2
0
 public function actionAdd()
 {
     $name = $_POST['name'];
     $description = $_POST['description'];
     $districtName = $_POST['districtName'];
     $district = new District();
     $district->name = $districtName;
     $district->save();
     $department = new Department();
     $department->name = $name;
     $department->description = $description;
     $department->district_id = $district->id;
     $department->save();
     $this->redirect(['/department/list']);
 }
예제 #3
0
 public function getDepartments()
 {
     return $this->hasMany(Department::className(), ['district_id' => 'id']);
 }