Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
Message: Call to a member function get_users() on a non-object

HI im using codeigniter and i'm very new to this. i doing a simple program that will show data from database. but i'm having errors! this is my code

Controller file User.php

class User extends CI_Controller{

    public function show(){

    $result= $this->user_model->get_users();

        foreach($result as $object)
        {
            echo $object->id;
            }
        }



    }

?>

Model file User_model.php

class User_model extends CI_Model {


    public function get_users(){

    $fetch= $this->db->get('User');
    return  $fetch->result();


        }

    }



?>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to load the model into your controller. The best way to load the model to write a constructor for controller and load all required model into it. Please find the code below :

public function __construct()
{
    parent::__construct();              
    $this->load->model('User_model');
}

Just copy and paste the code into your controller file and check. Hope it will do the work for you.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!