load model from folder in codeigniter

11,012

Solution 1

try this call constructor in controller and load model into it

function __construct()
    {
        // Initialization of class
        parent::__construct();

        // load the model
        $this->load->model('admin/myinterest_model');
    }

Solution 2

$this->load->model('admin/myinterest_model' , 'myinterest');

The second parameter (optional) is used to call the method.

ex:

$this->myinterest->get_users();
Share:
11,012
Zeeshan
Author by

Zeeshan

Updated on June 26, 2022

Comments

  • Zeeshan
    Zeeshan almost 2 years

    I am using codeigniter and handing admin side and users side separately. now i have model which is in admin folder and i want to call in controller of users. but when i am trying to load model from admin folder

    $this->load->model('admin/myinterest_model');
    
    $data['myInterest'] = $this->myinterest_model->selectResult('user',  $this->session->userdata['Id']);
    

    it shows following error

    Message: Undefined property: Users::$myinterest_model
    Filename: controllers/users.php
    

    Please guide me how to load model from admin

  • Zeeshan
    Zeeshan about 10 years
    i have already added myinterest_model in admin folder but now i need to access a function from admin/myinterest_model in user controller so when i try to load model as you mention it didn't works
  • Jakub
    Jakub about 10 years
    while a valid solution this isn't an answer, you are loading the model in construct or function, same thing.
  • Dexter
    Dexter about 10 years
    i know but do you have construct method in model and controller because its compulsory. i got same error because my controller have not a construct method