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

Subedi Kishor
  • 5,906
  • 5
  • 35
  • 53
Iqbal Hossain
  • 97
  • 3
  • 5
  • 16

3 Answers3

1

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

Junnel Gallemaso
  • 861
  • 2
  • 9
  • 23
0

Instead of

$this->index();

try this

header('Location:http://myipaddress/mysite/user');
GautamD31
  • 28,552
  • 10
  • 64
  • 85
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();

Gaurav Mehra
  • 471
  • 7
  • 20