Codeigniter PHP url segments for users profile
I need it so that when i type in domain.com/user/1 the one gets pulled in as a variable and th开发者_高级运维en can be used to get the correct database values. Right now the variable is set manually with domain.com/user . How do I setup the segments and then make get() that number. I'm working only with username url's as numbers so no, names just domain.com/user/1 , domain.com/user/487 ect
Take a look at URI Routing: http://codeigniter.com/user_guide/general/routing.html
Something like:
$route['user/(:num)'] = "user/user_lookup/$1";
in your config/routes.php file will probably do what you'd like.
as far as I understand you can pass the segment to your model when you call it in the controller with the URI like this
$this->usermode->get_user($this->uri->segment(3));
and recieve it in your model like a parameter
function get_user($user){
$this->db->where('userid', $user);
$query= $this->db->get('user');
if($query){
return $query->result();
}else{
return false;
}
}
I hope i understand correctly what you want to do
In your controller you could have a user function:
function user($id){
$this->db->where('userid',$id);
$q = $this->db->get('user');
$data['userdata']=$q;
$this->load->view('user_view',$data);
}
This will query the user
table in the database for the id
passed in the url, and send the results to the user_view
view. e.g. http://site.com/user/5
would query for user data that matched the userid
of 5.
精彩评论