Я получаю сообщение об ошибке с этой строкой:
$result = $this->user->login($username, $password);
Выполнение вызова метода или объекта, который не определен.
Контроллер:
<?php if (! defined('BASEPATH')) exit(' No direct script access allowed');
class verifyLogin extends CI_Controller{
function _contruct()
{
parent::_construct();
$this->load->model('User','',TRUE);
}
function index()
{
//validate the credentials
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username','trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password','trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//if validation fails then redirect to login page
$this->load->view('login_view');
}
else
{
//go to private area
redirect('home', 'refresh');
}
}
function check_database($password)
{
//validate against database
$username = $this->input->post('username');
//query the database
$result = $this->user->login($username, $password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'username' => $row->username
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
}
?>
Модель:
<?php
class User extends CI_Model
{
function login($username, $password)
{
$this-> db -> select('id, username, password');
$this-> db -> from('users');
$this-> db -> where('username = ' . "'" . $username . "'");
$this-> db -> where('password = ' . "'" . MD5($password) . "'");
$this-> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}
?>