コード例 #1
0
ファイル: userstate.php プロジェクト: NoguHiro/metro
 public function action_edit($id = null)
 {
     is_null($id) and Response::redirect('userstate');
     if (!($userstate = Model_Userstate::find($id))) {
         Session::set_flash('error', 'Could not find userstate #' . $id);
         Response::redirect('userstate');
     }
     $val = Model_Userstate::validate('edit');
     if ($val->run()) {
         $userstate->id = Input::post('id');
         $userstate->ride_state = Input::post('ride_state');
         $userstate->now_station_id = Input::post('now_station_id');
         $userstate->train_id = Input::post('train_id');
         $userstate->from_station_id = Input::post('from_station_id');
         $userstate->from_station_index = Input::post('from_station_index');
         $userstate->to_station_id = Input::post('to_station_id');
         $userstate->to_station_index = Input::post('to_station_index');
         $userstate->ticket_type = Input::post('ticket_type');
         $userstate->ticket_price = Input::post('ticket_price');
         if ($userstate->save()) {
             Session::set_flash('success', 'Updated userstate #' . $id);
             Response::redirect('userstate');
         } else {
             Session::set_flash('error', 'Could not update userstate #' . $id);
         }
     } else {
         if (Input::method() == 'POST') {
             $userstate->id = $val->validated('id');
             $userstate->ride_state = $val->validated('ride_state');
             $userstate->now_station_id = $val->validated('now_station_id');
             $userstate->train_id = $val->validated('train_id');
             $userstate->from_station_id = $val->validated('from_station_id');
             $userstate->from_station_index = $val->validated('from_station_index');
             $userstate->to_station_id = $val->validated('to_station_id');
             $userstate->to_station_index = $val->validated('to_station_index');
             $userstate->ticket_type = $val->validated('ticket_type');
             $userstate->ticket_price = $val->validated('ticket_price');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('userstate', $userstate, false);
     }
     $this->template->title = "Userstates";
     $this->template->content = View::forge('userstate/edit');
 }