Codeigniter:重定向不起作用
Codeigniter: Redirect not working
我已经搜索过这里的一些其他帖子,但我没能解决这个问题。不知道是什么问题
- 我正在尝试从
Login
控制器
logon/logout 后重定向到主 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');
}
}
我得到的只是 url http://localhost:85/login/logon
和一个空白屏幕。
我也尝试过:redirect('/home', 'refresh');
、redirect('/home');
、redirect('home', 'refresh');
、redirect('home/', 'refresh');
、redirect('/home/', 'refresh');
编辑:
这是开发工具中网络部分的响应:
这可能是由于 Chrome 重定向问题造成的,如此处 http://forums.asp.net/t/1599598.aspx?Response+Redirect+problem+in+Google+Chrome 所述。
您应该尝试其他浏览器以确定。如果是这样,那么您应该清除 Chrome 缓存。
如评论中所述,配置文件中的 base_url 必须使用尾部斜杠设置。在你的情况下:
$config['base_url'] = 'http://localhost:85/';
我已经搜索过这里的一些其他帖子,但我没能解决这个问题。不知道是什么问题
- 我正在尝试从
Login
控制器 logon/logout 后重定向到主
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');
}
}
我得到的只是 url http://localhost:85/login/logon
和一个空白屏幕。
我也尝试过:redirect('/home', 'refresh');
、redirect('/home');
、redirect('home', 'refresh');
、redirect('home/', 'refresh');
、redirect('/home/', 'refresh');
编辑:
这是开发工具中网络部分的响应:
这可能是由于 Chrome 重定向问题造成的,如此处 http://forums.asp.net/t/1599598.aspx?Response+Redirect+problem+in+Google+Chrome 所述。 您应该尝试其他浏览器以确定。如果是这样,那么您应该清除 Chrome 缓存。
如评论中所述,配置文件中的 base_url 必须使用尾部斜杠设置。在你的情况下:
$config['base_url'] = 'http://localhost:85/';