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();
}
}
?>
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.