Redirect error in codeIgniter

不羁的心 提交于 2019-12-26 00:15:23

问题


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?


回答1:


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.




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/9157293/redirect-error-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!