控制器/ verify_login.php頁笨無法加載模型
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Verify_login extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('adminl_model') ;
}
function index()
{
//This method will have the credentials validation
$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)
{
//Field validation failed. User redirected to login page
$this->load->view('admin/index');
}
else
{
//Go to private area
redirect('about', 'refresh');
}
}
function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->Admin_Model->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;
}
}
}
型號/ adminl_model.php頁
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
Class Adminl_Model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function login($username, $password)
{
$this -> db -> select('id, username, password','type');
$this -> db -> from('users');
$this -> db -> where('nick', $username);
$this -> db -> where('type', 'admin');
$this -> db -> where('pass', MD5($password));
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
return $query->result();
}
else
{
return false;
}
}
}
給出錯誤。我該如何解決這個問題?我正在致力於c9.io.和stackoverflow說這是如此codely。我明白我的問題很荒謬。使用
你會得到什麼錯誤? – 2014-09-28 07:58:58
$ this-> load-> model('adminl_model')或者die(「error」);所以只是錯誤文本 – 2014-09-28 08:03:49
和PHP給; 一個PHP錯誤遇到 嚴重性:注意 消息:未定義的屬性:Verify_login :: $ Admin_Model 文件名:控制器/ verify_login.php 行號:40 – 2014-09-28 08:06:33