php - Codeigniter 重定向不起作用

标签 php codeigniter

为什么重定向在这里不起作用。我正在调用未定义的函数 redirect()。

class Login extends CI_Controller {

    function index() {

        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
        $this->load->view('login_view');        

    }

    function authenticate() {

        $this->load->model('user_model');
        $query = $this->user_model->authenticate();

        if($query) {

            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );

            $this->session->set_userdata($data);
            redirect('/site/news_feed');

        }
        else {

            $this->index();

        }

    }

}

最佳答案

authenticate() 方法上方的顶部部分更改为此...

class Login extends CI_Controller {

    function __construct()
    {
        // this is your constructor
        parent::__construct();
        $this->load->helper('form');
        $this->load->helper('url');
    }

    function index()
    {
        //this is only called when someone does not specify a method...
        $this->load->view('login_view');        
    }
...

我强烈建议将这两个助手移动到自动加载,因为它们几乎是强制使用的......

关于php - Codeigniter 重定向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7082795/

相关文章:

php - 按时间戳选择 block 顺序并按 id 随机化

php - CI Active record,从多个表中选择记录

php - 删除和替换图像文件但仍然显示旧图像

PHP/jQuery Ajax/在 Ajax 处理页面中加载 xml

php - 如何在 html + php(codeIgniter) 中渲染一棵树

php - 无法使用 "npm run watch"编译 sass - Laravel

javascript - 不同的结果来自同一领域

javascript - 无法在 codeigniter 中自动刷新 div

php - 代码点火器 : how to update mulitiple record where id

PHP 上传脚本未发布