Ejemplo n.º 1
0
 /**
  * Действие для редактирования
  * 
  * @param int $id
  */
 public function action_edit($id = null)
 {
     is_null($id) and \Response::redirect_back('admin/competitions/tables');
     if (!($table = \Model_Table::find($id))) {
         \Session::set_flash('error', 'Таблица не найдена.');
         \Response::redirect_back('admin/competitions/tables');
     }
     $val = \Model_Table::validate('edit');
     if ($val->run()) {
         $table->results_json = \Input::post('results_json');
         $table->season_id = \Input::post('season_id');
         $table->show_on_main = \Input::post('show_on_main');
         if ($table->save()) {
             \Session::set_flash('success', 'Updated table #' . $id);
             \Response::redirect_back('admin/competitions/tables');
         } else {
             \Session::set_flash('error', 'Could not update table #' . $id);
         }
     } else {
         if (\Input::method() == 'POST') {
             $table->results_json = $val->validated('results_json');
             $table->season_id = $val->validated('season_id');
             $table->show_on_main = $val->validated('show_on_main');
             \Session::set_flash('error', $val->error());
         }
         $this->template->set_global('table', $table, false);
     }
     $this->template->content = \View::forge('competitions/tables/edit');
 }