codeigniter 重定向到不同的控制器
当用户获得授权时,我试图将用户引导至我的主页。我正在登录登录检查控制器中进行用户检查并添加 $this->load->view('main');
页面可以加载,但主页中的站点地址仍然显示
但我希望它显示
我是否必须创建一个新的“主”控制器并加载视图?这对我来说听起来多余。这是我的代码。
我的 login_check.php
的一部分
private function _user_check()
{
$this->load->model('user_query'); //load my model
$result=$this->user_query->query($this->input->post('username'),$this->input->post('password'))
if($result) //the user is in DB
{
$data['view']='main';
$this->load->view('include/template', $data);
//the address bar shows http://myproject/login_check in main page
}else{ //the user is not in DB
$data['view']='login';
$this->load->view('include/template', $data);
}
}
I am trying to direct the user to my main page when the user is authorized. I am doing the user check in my login_check controller and add $this->load->view('main');
The page can be load but the site address in the main page still show
but I want it to show
Do i have to create a new 'main' controller and load the view? It sounds redundant to me. Here is my code.
part of my login_check.php
private function _user_check()
{
$this->load->model('user_query'); //load my model
$result=$this->user_query->query($this->input->post('username'),$this->input->post('password'))
if($result) //the user is in DB
{
$data['view']='main';
$this->load->view('include/template', $data);
//the address bar shows http://myproject/login_check in main page
}else{ //the user is not in DB
$data['view']='login';
$this->load->view('include/template', $data);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
首先,您在检查用户是否经过身份验证方面做得非常差(仅将用户名/通行证传递给模型并不是最好的,应该在发送到模型之前对其进行处理/检查)。
您可以通过包含帮助程序“URL”轻松进行重定向,只需使用:
或在现实世界中的示例:
参考链接
First of all, you are doing a very poor job of checking if the user is authenticated (just passing username/pass to model isn't best, should process / check it before sending to model).
You can make redirects easily by including the helper 'URL' and simply use:
or in a real world example:
Reference Link