在codeigniter的管理登录进程中没有获取值 [英] Values are not getting fetched in admin login process in codeigniter
本文介绍了在codeigniter的管理登录进程中没有获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已创建一个名为Admin.php的控制器
I Have created a controller named Admin.php
class Admin extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index($msg = NULL) {
$data['msg'] = $msg;
$this->load->view('pages/sign-in');
}
public function process(){
// Load the model
$this->load->model('admin/Admin_model');
// Validate the user can login
$result = $this->Admin_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$msg = '<font color=red>Invalid username and/or password.</font><br />';
$this->index($msg);
}else{
// If user did validate,
// Send them to members area
redirect(base_url().'home');
}
}
and model is
class Admin_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('wc_watchconnect_adminlogin');
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->id,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
另一个控制器是home
one more controller is home
class Home extends CI_Controller {
function __construct(){
parent::__construct();
$this->check_isvalidated();
}
public function index(){
$this->load->view('pages/index');
}
private function check_isvalidated(){
if(! $this->session->userdata('validated')){
redirect(base_url().'index.php/admin');
}
}
}
?>
在此$ result中显示空值,它为空白,而我有username = admin和password = admin在数据库...值没有获取在$结果pls帮助我摆脱这...感谢提前
in this $result is showing null value it is blank while i have username=admin and password=admin in database ... values are not getting fetch in $result pls help me to get rid out of this... thanks in advance
推荐答案
您需要更改
if($query->num_rows == 1)
至
if($query->num_rows() == 1)
添加 / code>
num_rows
阅读 num_rows()
if ($query->num_rows() == 1) {
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->id,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
} else {
// If the previous process did not validate
// then return false.
return false;
}
这篇关于在codeigniter的管理登录进程中没有获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文