php - Error Fatal error: Call to a member function insert() on a non-object -
i'm using callback after inserting in database, pass values other table, think method used fine. gives me error when inserting other table in database, in model, or in controller im kind of clueless in error, can please me. before put $this->load->database(); in autoload in config file :)
fatal error: call member function insert() on non-object
a php error encountered
severity: notice
message: undefined property: finances::$inventory_model
filename: controllers/finances.php
line number: 125
controller:
public function inventory_management($post_array,$primary_key) { $this->load->model('inventory_model'); if($post_array['id_expense']!=null){ $type = 'add'; $id_exp_detail = $primary_key; $result = $this->inventory_model->insert([ 'id_exp_detail' => $id_exp_detail, 'name' => $post_array['brand'], 'quantity' => $post_array['item_quantity'], 'lote' => $post_array['package_code']; 'type' => $type, 'date' => date(), 'id_user' => $this->session->userdata('id_user'), 'id_entity' => $this->session->userdata('id_entity') ]); }else if ($post_array['name']!=null){ $type = 'sub'; $id_treatment = $primary_key; $result = $this->inventory_model->insert([ 'id_treatment' => $id_treatment, 'name' => $post_array['name'], 'quantity' => $post_data['recomended_dose'], 'lote' => $post_array['id_package'], 'type' => $type, 'date' => date(), 'id_user' => $this->session->userdata('id_user'), 'id_entity' => $this->session->userdata('id_entity') ]); }else{ $type = 'sub'; $id_fertilization = $primary_key; $result = $this->inventory_model->insert([ 'id_fertilization' => $id_fertilization, 'name' => $post_data['name'], 'quantity' => $post_data['quantity'], 'lote' => $post_data['id_package'], 'type' => $type, 'date' => date(), 'id_user' => $this->session->userdata('id_user'), 'id_entity' => $this->session->userdata('id_entity') ]); } if($result){ echo "validation complete"; } }
model
class crud_model extends ci_model { protected $_table = null; protected $_primary_key = null; // ------------------------------------------------------------------------ public function __construct() { parent::__construct(); } public function insert($data) { $this->db->insert($this->_table, $data); // return $this->db->insert_id(); }
model:
class inventory_model extends crud_model { protected $_table = 'inventory_management'; protected $_primary_key = 'id'; // ------------------------------------------------------------------------ public function __construct() { parent::__construct(); } // ------------------------------------------------------------------------ }
here wrong call wrong model file
$this->load->model('inventory_model');
it should be
$this->load->model('crud_model');
and use wrong way pass array in function
$param = array('id_exp_detail' => $id_exp_detail, 'name' => $post_array['brand'], 'quantity' => $post_array['item_quantity'], 'lote' => $post_array['package_code'], 'type' => $type, 'date' => date(), 'id_user' => $this->session->userdata('id_user'), 'id_entity' => $this->session->userdata('id_entity')); $result = $this->inventory_model->insert($param);
Comments
Post a Comment