2017-02-23 57 views
0

登录后,我有一个登录页面,我有两个user_types..one是供应商,另一种是用户..获得用户ID在URL中笨

So..what我想要做的是,每当用户或供应商从login..they登录都重定向到dashboard..in,我想在URL中的USER_ID ..

这里是我的登录控制器:

公共职能登入() {

$data['error'] ="Invalid Login"; 
      if($this->input->post()) 
      { 

       $user = $this->LoginModel->login($this->input->post()); 
       if(count($user)>0) 
       { 
         $data = array(
          'user_id' => $user['user_id'], 
          'first_name' => $user['first_name'], 
          'email' => $user['email'], 
          'password' => $user['password'] 
          ); 

       $this->session->set_userdata($data); 



      if($user['user_type_id'] == '1') 
      { 

        redirect(base_url('index.php/Login/vendor_dashboard')); 

      } 


     elseif($user['user_type_id'] == '2') 
     { 
       redirect(base_url('index.php/Login/user_dashboard')); 
     } 

     else 
     { 
      redirect(base_url('index.php/Login/dashboard')); 
     } 

     } 
    else 
    { 
     $data["error_message"]="Invalid User Name and Password combination"; 
    } 
} 

$ this-> load-> view('Admin/login_view',$ data);

}

这是我的模型:

function login($post='') 
{ 
$this->db->where(array('email' => $post['email'], 'password' => $post['password'])); 
$query = $this->db->get('users'); 

return $query->row_array(); 
} 

请人帮助我..

如何做到这一点..提前

谢谢..

回答

1

你会做这样的事情 编辑制作

redirect(base_url('index.php/Login/user_dashboard/'.$this->session->user_id); 
+0

,那么你可以用$这个 - 它访问> URI->段(3);在你打电话的函数 –

+0

它的工作..感谢你..感谢很多.. – M5533

+0

请注意我所做的改变,我的意思是它没有真正必要的,但我已经chaged连接,而不是从会话中获取数据访问阵列.......也请接受我的答案,如果它有帮助 –

1

试试这个:

redirect(base_url('index.php/Login/vendor_dashboard?user_id='.$user['user_id']) 
+0

我有另一个怀疑..在仪表板用户有3个标签..当他们点击第一个标签的页面将重定向到特定的页面..在该页面我也需要调用该user_id ..你可以告诉我怎么可以我做临时工 – M5533