Пример #1
0
 /**
  * Action after create, register relation
  * @param Model_ORM $model
  * @param int $id
  * @param array $value
  * @return mixed 
  */
 public function after_create($model, $id = null, $value = null)
 {
     if ($this->item['edit'] != FALSE) {
         if (empty($value)) {
             $value = CRUD_Tools::post_param($this->item['name']);
         }
         $model = ORM::factory($this->model->object_name(), $id);
         $model->add($this->item['name'], $value);
     }
     return null;
 }
Пример #2
0
 public static function init(Kohana_Request $request, Kohana_Response $response)
 {
     self::$request = $request;
     self::$response = $response;
 }
Пример #3
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();
 }