Пример #1
0
 /**
  * Edit new item
  */
 public function action_edit()
 {
     $id = $this->request->param('id');
     $view = new View('crud/' . $this->view . '/edit');
     $view->errors = array();
     if ($id == null) {
         $this->request->redirect($this->base_controller . $this->controller_name . '/show/');
     }
     if ($this->request->method() == 'POST') {
         try {
             $this->model->save_update(CRUD_Tools::all_param(), $id);
             //$this->model->clear();
             if ($this->request->post('submit_next')) {
                 $this->request->redirect($this->base_controller . $this->controller_name . '/add/');
             } else {
                 if ($this->request->post('submit_previous')) {
                     $this->request->redirect($this->base_controller . $this->controller_name . '/show/');
                 } else {
                     $this->request->redirect($this->base_controller . $this->controller_name . '/edit/' . $id);
                 }
             }
         } catch (ORM_Validation_Exception $e) {
             //throw orm validation exception and send to view
             $view->errors = $e->errors('validations');
         } catch (Validation_Exception $e) {
             //throw validation exception and send to view
             $view->errors = $e->array->errors('validations');
         }
     }
     $view->id = $id;
     $view->base_controller = $this->base_controller;
     $view->name = $this->controller_name;
     $view->data = $this->model->get_for_edit($id);
     $view->columns = (object) array('left' => array(), 'right' => array());
     foreach ($this->model->get_items() as $name => $column) {
         if ($column->is_edit() and $column->get_position() == 'left') {
             $view->columns->left[$name] = $column;
         } else {
             if ($column->is_edit() and $column->get_position() == 'right') {
                 $view->columns->right[$name] = $column;
             }
         }
     }
     $this->template->content = $view->render();
 }