2016-11-09 69 views
0

我正在創建一個包含註冊的待辦事項列表。我命名我的默認控制器的主要和使用它到register/login,在本地主機的索引頁看起來像http://localhost/todo/main/但是,登錄後我不想顯示localhost/main/todolist而是localhost/todolist我是否必須創建一個新的控制器?在CI中使用多個控制器是否實用?Codeigniter多個控制器

routes.php現在

$route['default_controller'] = 'main'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 
+0

所以基本上你只是想通過'http://本地主機/ todo' URL時,得到了用戶在你的網站登錄? –

+0

@HabibRehman確切地說是 – Radu033

+0

你是否也在'main'控制器上對用戶進行身份驗證? –

回答

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

} 
+0

謝謝老兄,我明白了:) – Radu033

+0

樂意幫忙:) –