If there's someone logged in, this code checks the sessions and I can successfully view the page, but now I'd like to check if the user is admin. I've tried checking for this in the model and I keep getting a few errors. One of them is "Fatal error: Call to undefined function where() in C:\xampp\htdocs \ecwm604\applic ation\models\us ermodel.php on line 54"
The line
Error is taking place on line 5 below:
Code:
public function index()
{
$this->load->library('authlib');
$loggedin = $this->authlib->is_loggedin();
///$admin = $this->auth->admin();
if ($loggedin === false) {
$this->load->helper('url');
redirect('/auth/login');
}
if ($this->auth->admin() === false) {
$message ['msg'] = "You are not an admin!";
$this->load->view('homeview', $message);
}
else
{
$this->load->view('add_view');
}
}
$this->admin($usernam e,$password); passes to admin() belowCode:
--Controller Auth
public function authenticate()
{
$username = $this->input->post('uname');
$password = $this->input->post('pword');
$user = $this->authlib->login($username,$password);
>> $this->admin($username,$password); <<passes to admin()below
if ($user !== false) {
$this->load->view('homeview',array('name' => $user['name']));
}
else {
$data['errmsg'] = 'Unable to login - please try again';
$this->load->view('login_view',$data);
}
}
public function admin($username,$password){
//$this->load-model('usermodel');
$admin = $this->authlib->adminlib($username,$password);
if ($admin == false){
return false;
//if ($res->num_rows() != 1){
//return false;
}
}
Code:
--Library Authlib
public function adminlib($user,$pwd)
{
return $this->ci->usermodel->chkadmn($user,$pwd);
}
Code:
--Model Usermodel
function chkadmn($username,$password)
{
<<This is where the error is taking place>>$this->db-where(array('username' => $username,'password' => sha1($password)));
$res = $this->db->get('users',array('type'));
if ($res->num_rows() != 1) {
return false;
}
}
Comment