我有一个带有名称仪表板的PHP CodeIgniter控制器,并且该控制器位于管理员命名文件夹中,我尝试使用url =>' admin / dashboard'登录管理仪表板。但它没有显示任何内容并将我重定向到登录页面。
class Dashboard extends Admin_Controller {
public function __construct() {
parent::__construct();
$this->load->model('admin_model');
}
public function index() {
$data['title'] = "Care Your Car";
$employee_id = $this->session->userdata('employee_id');
//total employee count
$this->admin_model->_table_name = "tbl_employee"; //table name
$this->admin_model->_order_by = "employee_id"; // order by
$data['employee'] = $this->admin_model->get_by(array('status' => 1)); // get resutl
$data['total_employee'] = count($this->admin_model->get()); // get resutl
$data['subview'] = $this->load->view('admin/main_content', $data, TRUE);
$this->load->view('admin/_layout_main', $data);
}
<?php
class Login_Model extends MY_Model {
protected $_table_name;
protected $_order_by;
public $rules = array(
'user_name' => array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email'
),
'password' => array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required'
)
);
public function login() {
//check user type
$this->_table_name = 'tbl_employee_login';
$this->_order_by = 'employee_login_id';
$employee = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
'activate' => 1
), TRUE);
/*employee*/
$this->_table_name = 'driver';
$this->_order_by = 'driver_id';
$driver = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
), TRUE);
/*driver*/
$this->_table_name = 'tbl_user';
$this->_order_by = 'user_id';
$admin = $this->get_by(array(
'email' => $this->input->post('email'),
'password' => $this->input->post('password'),
), TRUE);
if ($admin) {
$data = array(
'email' => $admin->email,
'first_name' => $admin->first_name,
'last_name' => $admin->last_name,
'employee_id' => $admin->user_id,
'loggedin' => TRUE,
'user_type' => 1,
'user_flag' => $admin->flag,
'url' => 'admin/dashboard',
);
$this->session->set_userdata($data);
} elseif($employee) {
if (count($employee)) {
// Log in user
$employee_id = $employee->employee_id;
$this->_table_name = "tbl_employee"; //table name
$this->_order_by = "employee_id";
$user_info = $this->get_by(array('employee_id' => $employee_id), TRUE);
$data = array(
'email' => $employee->email,
'employee_id' => $employee->employee_id,
'user_name' => $user_info->first_name . ' ' . $user_info->last_name,
'employee_login_id' => $employee->employee_login_id,
'loggedin' => TRUE,
'user_type' => 2,
'url' => 'employee/dashboard',
);
$this->session->set_userdata($data);
}
}
elseif($driver){
$data = array(
'email' => $driver->email,
'drive_id' => $driver->driver_id,
'name' => $driver->name,
'loggedin' => TRUE,
'user_type' => 3,
'url' => 'driver/dashboard',
);
$this->session->set_userdata($data);
}
}
public function logout() {
$this->session->sess_destroy();
}
public function loggedin() {
return (bool) $this->session->userdata('loggedin');
}
public function hash($string) {
return hash('sha512', $string . config_item('encryption_key'));
}
}
class Login extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->model('admin_model');
}
public function index() {
//$this->session->sess_destroy();
$dashboard = $this->session->userdata('url');
$this->login_model->loggedin() == FALSE || redirect($dashboard);
$rules = $this->login_model->rules;
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == TRUE) {
// We can login and redirect
if ($this->login_model->login() == TRUE) {
redirect($dashboard);
} else {
$this->session->set_flashdata('error', 'Username / Password combination does not exist');
redirect('login', 'refresh');
}
}
$data['title'] = "User Login";
$data['subview'] = $this->load->view('login', $data, TRUE);
$this->load->view('login', $data);
}
{我想登录管理员dashborad但是我不能,当我尝试在登录表单中输入用户名和密码并按回车键再次显示登录页面而不是仪表板请帮我修复}