【发布时间】:2015-02-22 15:00:53
【问题描述】:
我已经在这里搜索了一些其他类似问题的帖子,但我还没有设法完成这项工作。不知道是什么问题。
- 从
Login控制器登录/注销后,我正尝试重定向到主Home控制器
我在我的开发环境变量中设置了error_reporting(E_ALL) 并且没有错误并尝试在我的Login 控制器中加载url 帮助程序:$this->load->helper('url');
这里是主要的Home 控制器:
public function index() {
if (($this->session->userdata('username') != "")) {
$this->user();
} else {
$this->load->view('login');
}
}
这是Login 控制器:
public function index()
{
$this->load->view('login');
}
public function logout()
{
$profile = array(
'userid' => '',
'username' => '',
'role' => '',
'custid' => '',
'custname' => '',
'logged_in' => FALSE
);
$this->session->unset_userdata($profile);
$this->session->sess_destroy();
redirect('/', 'refresh');
}
public function logon()
{
$data = $_POST;
$this->db->select("people.*, customers.name as 'custname', customers.id as 'custid'");
$this->db->from('people');
$this->db->join('customers', 'customers.id = people.customer');
$this->db->where('people.username', $data['username']);
$this->db->where('people.password', $data['password']);
$query = $this->db->get();
$results = $query->result_array();
if(count($results) > 0)
{
$profile = array(
'username' => $results[0]['username'],
'userid' => $results[0]['id'],
'role' => $results[0]['role'],
'date_format' => $results[0]['date_format'],
'custname' => $results[0]['custname'],
'custid' => $results[0]['custid'],
'logged_in' => TRUE
);
$this->db->select("*");
$this->db->from('hub.settings');
$this->db->where('customer', $profile['custid']);
$query = $this->db->get();
$results = $query->result_array();
if(count($results) > 0)
{
$profile['contacthtml'] = $results[0]['contacthtml'];
$profile['accentcolor'] = $results[0]['accentcolor'];
}
$this->session->set_userdata($profile);
redirect('/', 'refresh');
}else{
redirect('/login', 'refresh');
}
}
我得到的只是网址 http://localhost:85/login/logon 和一个空白屏幕。
我也试过:redirect('/home', 'refresh');、redirect('/home');、redirect('home', 'refresh');、redirect('home/', 'refresh');、redirect('/home/', 'refresh');
编辑:
这是来自开发工具中网络部分的响应:
【问题讨论】:
-
你确定
count($results)是> 0吗?因为redirect("home")应该足够了。 (附带说明,您的控制器中不应该有查询,它们属于模型) -
是的,我刚刚检查了 if 中的
&results变量,它有值(在您的旁注中,为了简单起见) -
如果你放置
die("hello");而不是你的redirect("home"),你看到你好了吗? -
你忘记了斜杠:
$config['base_url'] = 'http://localhost:85/'; -
@AdrienXL:是的,谢谢 AdrienXL,解决了它,你应该发布答案,以便我接受。
标签: php codeigniter redirect