Users.php Controller
class Users extends CI_Controller{
public function userList(){
$data['results'] = $this->user_model->get_users();
$this->load->view('users_view',$data);
}
}
user_model.php Model
class User_model extends CI_Model{
public function get_users()
{
$query = $this->db->get('users');
return $query->result();
}
}
users_view.php View
foreach ($results as $list) {
echo $list->id;
}
main.php View
$this->load->view('users_view');
When i view http://localhost:81/rokki/users/userlist the id is displayed. But, when i view in http://localhost:81/rokki/home thru the main.php I'm getting errors as below :
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: results
Filename: views/users_view.php
Line Number: 41
Backtrace:
File: C:\xampp\htdocsokki\application\views\users_view.php Line: 41 Function: _error_handler
File: C:\xampp\htdocsokki\application\views\layouts\main.php Line: 20 Function: view
File: C:\xampp\htdocsokki\application\controllers\Home.php Line: 7 Function: view
File: C:\xampp\htdocsokki\index.php Line: 315 Function: require_once
I'm newbie to the CI. Please help me. Thanks in advance