0

I'm creating a todo list with registration. I named my default controller main and use it to register/login, on localhost the index page looks like http://localhost/todo/main/ however, after logging in I don't want to show localhost/main/todolist but rather localhost/todolist do I have to create a new controller for that? Is it practical to use multiple controllers in CI?

My routes.php now is

$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
7
  • so basically you just want ` localhost/todo` url when you got user logged in your site ? Commented Nov 9, 2016 at 19:48
  • @HabibRehman exactly Commented Nov 9, 2016 at 19:48
  • are you doing authentication of user on main controller as well ? Commented Nov 9, 2016 at 19:58
  • @HabibRehman yes, the users, logins/registers on main controller but once he is logged in I want it to be in a separate controller. Is this practical in CI or I should do it somehow else? By the way do you know how to check if the session exists? Commented Nov 9, 2016 at 20:00
  • yes why not, before i add my answer could you please paste your main controller code here ? so that i could answer accordingly @Radu033 Commented Nov 9, 2016 at 20:02

1 Answer 1

1
<?php

  public function login_validation(){
    $this->load->library('form_validation');

    $this->form_validation->set_rules('email','Email','required|trim|callback_validate_credentials');
    $this->form_validation->set_rules('password','Password','required|md5|trim');

    /*******************************
     Little modification so that i'll come in this block if form has everything right in it 
    **********************************/  
    if($this->form_validation->run() !== FALSE){

     /******************
      Also you should now check these user inputs against DB values to make sure if this user exists. you may use e.g 
      ***************/
       $result = $this->db->get_where('table_name',array('table_colum',$this->input->post('form_field_name')))->row();
     if($result)
     {
        $data = array(
            'username'=>$this->input->post('username'),
            'email'=>$this->input->post('email'),
            'is_logged_in'=> 1
            );
        $this->session->set_userdata($data);

        // This should be the new controller where you want to take 
        // your user but by passing its ravelent data, you can do it like 

         redirect('lists',$data); 
       //create new controller and put that name here for 'lists'
    } else {
        $this->load->view('login');
    }

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

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.