【发布时间】:2015-12-26 09:14:00
【问题描述】:
我是 CI 的新手,我正在尝试使用我自己的数据从控制器内部的方法将用户重定向到视图,如下所示:
class Welcome extends CI_Controller {
public function doLogin() {
extract($_POST);
$this->load->library("form_validation");
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if ($this->form_validation->run() == FALSE)
{
exit;
}
else {
if ($this->welcome_model->loginuser($email,$password)==true) {
header("Location: ".base_url()."explore");
}
else {
$data['errors'][] = "Email and password do not match.";
$this->load->view('header');
$this->load->view('welcome',$data);
}
return true;
}
}
}
如您所见,下半部分应该加载 /welcome, 而是加载 /welcome/doLogin
有没有办法像构造函数一样加载视图?所以它只会加载 /welcome 吗?
【问题讨论】:
-
去掉 return true 然后再试一次。
-
只是一些提示:如果您碰巧使用 CI 之类的框架,也请使用重定向方法 - 因此,请考虑使用
redirect(),而不是header()。此外,这里不需要 return 语句(函数退出、重定向或加载视图)。关于您的问题,您的控制器的其他代码是什么?也许把它给pastebin.com -
谢谢,不知道 CI 中存在 redirect()。删除 return true 并没有帮助。
-
删除
return true并使用公共函数index()
标签: php codeigniter