コード例 #1
0
 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 getDistrict()
 {
     return $this->hasOne(District::className(), ['id' => 'district_id']);
 }