0

I am new in CodeIgniter. I am getting a problem. My procedure seems logical but it would not work!

I have a controller: User

class User extends CI_Controller {

    public function __construct()   {
        parent::__construct();
        $this->load->model('user_model');  
    }

    public function index($slug = FALSE) {
        $data['title'] = "User List";
        if($slug === FALSE) {
            $data['user'] = $this->user_model->get_user();      
        } else {
            $data['user'] = $this->user_model->get_user($slug);      
        }    
        if (empty($data['user'])){
            show_404();
        }
        $this->load->library('table');        
        $this->load->view('user_view', $data);    
    }

    public function authen() {
        $this->load->helper('form');
        $this->load->library('form_validation');    

        $this->form_validation->set_rules('phone', 'phone', 'required');
        $this->form_validation->set_rules('password', 'password', 'required');

        if ($this->form_validation->run() === FALSE) {
            $this->load->view('login_form');
        } else {
            if($this->user_model->do_login()===TRUE) {
                $this->index();
            }      
            $this->authen();                   
        }
    }
}

The "authen" method is not working properly with its last conditions. Page does not redirect to controller.

Can anybody help? Thanks

3 Answers 3

1

You can use: redirect('user') it will redirect u to the controller user class

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, It works. But why not the $this->index() not working? In fact several google sites is saying so..
0

Instead of

$this->index();

try this

header('Location:http://myipaddress/mysite/user');

Comments

0

You are try to load the login page in case there is any authentication error.

For for this you will need to bring user to the login page again.

use redirect('user/login'); and store the error message in session flash.

or display validation errors..

you cannot call controller from a controller. as $this->index();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.