codeigniter 重定向到不同的控制器

发布于 12-28 03:01 字数 1110 浏览 2 评论 0原文

当用户获得授权时,我试图将用户引导至我的主页。我正在登录登录检查控制器中进行用户检查并添加 $this->load->view('main'); 页面可以加载,但主页中的站点地址仍然显示

http://myprojectname/login_check

但我希望它显示

http://myprojectname/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

http://myprojectname/login_check

but I want it to show

http://myprojectname/main.

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

万劫不复2025-01-04 03:01:54

首先,您在检查用户是否经过身份验证方面做得非常差(仅将用户名/通行证传递给模型并不是最好的,应该在发送到模型之前对其进行处理/检查)。

您可以通过包含帮助程序“URL”轻松进行重定向,只需使用:

redirect('/controller/method');

或在现实世界中的示例:

redirect('/main');

参考链接

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:

redirect('/controller/method');

or in a real world example:

redirect('/main');

Reference Link

梦幻的味道2025-01-04 03:01:54

还有另一种方法,但类似于redirect(),如果你的控制器是Rest控制器

restserver

你可以使用在另一个控制器中休息客户端以调用服务器控制器上的方法

restclient

There is another way but similar to redirect(), if your controller is Rest controller

restserver

You can use rest client in another controller to call methods on the server controller

restclient

暖风昔人2025-01-04 03:01:54
redirect('controller/function');

例如你可以有
redirect('auth/login'); 路由为

$route['auth/login'] = 'auth/auth/index';
redirect('controller/function');

For example you can have
redirect('auth/login'); with routes as

$route['auth/login'] = 'auth/auth/index';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文