Redirect error in codeIgniter

2019-09-20 00:44发布

I am trying to the code

function validate(){
        $this->load->library('session');
        $this->load->model('inventory/inventoryModel');
        $result = $this->inventoryModel->validateUser();
        if($result == 1){
            $data = array(
                'username' => $this->input->post('username'),
                'is_loged_in' => TRUE 
            );
            $this->session->set_userdata($data);
        }
        else{
            $this->index();
            redirect('inventory/validate');
        }
    }

and getting the error in chrome "This web page has a redirect loop" what is solution?

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-20 01:11

You probably call the validate function in your index function as well. Maybe you need to adds some logic to only run validate when not in index.

查看更多
Explosion°爆炸
3楼-- · 2019-09-20 01:12

You have

$this->index() 

which probably trying to load views mentioned in the function.

Redirect causing again to load different function.

Sort that out. Can't give the exact solution as this isn't the whole code.

查看更多
三岁会撩人
4楼-- · 2019-09-20 01:20

Try This:

function validate(){
        $this->load->library('session');
        $this->load->model('inventory/inventoryModel');
        $result = $this->inventoryModel->validateUser();
        if($result == 1){
            $data = array(
                'username' => $this->input->post('username'),
                'is_loged_in' => TRUE 
            );
            $this->session->set_userdata($data);
        }
        else{
            $this->index();
        }
    }
查看更多
登录 后发表回答