简体   繁体   中英

Error Fatal error: Call to a member function insert() on a non-object

I'm using a callback after inserting in the database, to pass values to this other table, i think the method i used its fine. But it gives me this error when its inserting to the other table in the database, probably in my model, or something in the controller im kind of clueless in this error, can someone please help me. Before someone say its to put $this->load->database(); its already in my autoload in config file :)

Fatal error: Call to a member function insert() on a non-object

A PHP Error was 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 is the wrong you call wrong model file

$this->load->model('inventory_model');

it should be

$this->load->model('crud_model');

and you use wrong way to 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM