Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter redirect not working

Why isn't redirect working here. I'm getting call to undefined function 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();

        }

    }

}
like image 307
el_pup_le Avatar asked Nov 29 '22 18:11

el_pup_le


2 Answers

Try:

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

If your server is windows, try:

redirect('/site/news_feed','refresh');
like image 29
Alfonso Rubalcava Avatar answered Dec 05 '22 17:12

Alfonso Rubalcava


Change the top portion above your authenticate() method to this...

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');        
    }
...

I would strongly recommend moving these two helpers to be autoloaded because of their almost manditory use...

like image 108
jondavidjohn Avatar answered Dec 05 '22 17:12

jondavidjohn