/** * Save one item instance * */ public function save() { $id_item_definition = $this->input->post('id_item_definition'); $id_item = $this->item_model->save($id_item_definition, $_POST); $item = $this->item_model->get(array('id_item' => $id_item)); $this->xhr_output($item); $this->success(lang('ionize_message_operation_ok')); }
public function add() { include '_checksession.php'; $this->load->library('form_validation'); $this->load->helper('form'); $this->load->model('shop_model'); $shops = $this->shop_model->get(); $shop_dropdown = array(); foreach ($shops as $id => $shop) { $shop_dropdown[$id] = $shop->name; } $this->form_validation->set_rules(array(array('field' => 'brand', 'label' => 'Brand', 'rules' => ''), array('field' => 'name', 'label' => 'Item Name', 'rules' => 'required'), array('field' => 'price', 'label' => 'Price', 'rules' => 'required|numeric|callback_val_zero|max_length[6]'), array('field' => 'qty', 'label' => 'Quantity', 'rules' => 'required|numeric|callback_val_zero|max_length[6]'))); $this->form_validation->set_error_delimiters('<div class="alert alert-danger">' . '<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>', '</div>'); $unit = ['pack' => 'pack', 'piece' => 'piece', 'L' => 'L', 'mL' => 'mL', 'g' => 'g', 'kg' => 'kg', 'mg' => 'mg', 'lb' => 'lb', 'oz' => 'oz']; if (!$this->form_validation->run()) { $this->load->view('item_form', array('shop_dropdown' => $shop_dropdown, 'unit' => $unit)); } else { $this->load->model(array('item_model', 'price_model')); $item = new Item_model(); $item->brand = $this->input->post('brand'); $item->name = $this->input->post('name'); $item->qty = $this->input->post('qty'); $item->unit = $this->input->post('unit'); $item->save(); $price = new Price_model(); $price->user_id = $this->session->user_id; $price->item_id = $this->db->insert_id(); // Can't brain the logic %$#@! $price->shop_id = $this->input->post('shop'); //Same $price->price = $this->input->post('price'); $price->datetime = date('Y-m-d H:i:s'); $price->save(); $this->load->view('item_form_success', array('item' => $item)); } }