Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter redirect to different controller

Tags:

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

}
like image 804
FlyingCat Avatar asked Jan 20 '12 16:01

FlyingCat


1 Answers

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

like image 101
Jakub Avatar answered Sep 23 '22 11:09

Jakub