Codeigniter多个控制器

时间:2016-11-09 19:22:17

标签: php codeigniter codeigniter-3

我正在创建一个带注册的待办事项列表。我命名我的默认控制器main并将其用于register/login,在localhost上索引页面看起来像http://localhost/todo/main/但是,登录后我不想显示localhost/main/todolist而是{ {1}}我必须为此创建一个新的控制器吗?在CI中使用多个控制器是否切实可行?

我的localhost/todolist现在是

routes.php

1 个答案:

答案 0 :(得分: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');
    }

}