Reputation: 937
I am having trouble retrieving and putting the user id in the url into a variable. Here is my controller that I am trying to do this with. I have read the documentation in the user guide,however I am not getting any results.
here is my url structure:
clci.dev/account/profile/220
Controller:
public function profile()
{
$this->load->helper('date');
$this->load->library('session');
$session_id = $this->session->userdata('id');
$this->load->model('account_model');
$user = $this->account_model->user();
$data['user'] = $user;
$data['session_id'] = $session_id;
//TRYING TO MAKE A VARIABLE WITHT THE $_GET VALUE
$user_get = $this->input->get($user['id']);
echo $user_get;
if($user['id'] == $session_id)
{
$data['profile_icon'] = 'edit';
}
else
{
$data['profile_icon'] = 'profile';
}
$data['main_content'] = 'account/profile';
$this->load->view('includes/templates/profile_template', $data);
}
Am I flat out doing this wrong, or are there adjustments that I need to make in my config files?
thanks in advance
Upvotes: 0
Views: 1872
Reputation: 2411
you can directly get like this:
public function profile($user_id = 0)
{
//So as per your url... $user_id is 220
}
Upvotes: 0
Reputation: 1179
I suppose at this point that the value for $_GET['id'] is intended to be 220 so here: To get 220, you would have to do it this way (except the get value in question is other than 220 as shown in your url above)
Let's say you visit: clci.dev/account/profile/220. Follow the comments for more info.
public function profile()
{
$this->load->helper('url'); //Include this line
$this->load->helper('date');
$this->load->library('session');
$session_id = $this->session->userdata('id'); //Ensure that this session is valid
$this->load->model('account_model');
$user = $this->account_model->user(); //(suggestion) you want to pass the id here to filter your record
$data['user'] = $user;
$data['session_id'] = $session_id;
//TRYING TO MAKE A VARIABLE WITHT THE $_GET VALUE
$user_get = $this->uri->segment(3); //Modify this line
echo $user_get; //This should echo 220
if($user_get == $session_id) //Modify this line also
{
$data['profile_icon'] = 'edit';
}
else
{
$data['profile_icon'] = 'profile';
}
$data['main_content'] = 'account/profile';
$this->load->view('includes/templates/profile_template', $data);
}
I hope that helps your gets your started in the right track.
Upvotes: 0
Reputation: 5371
You would set up your controller function as follows
public function profile($id = false)
{
// example: clci.dev/account/profile/222
// $id is now 222
}
Upvotes: 2
Reputation: 3132
In codeigniter, instead of having something.com/user.php?id=2
we use something.com/user/2
and the way to get that 2 is using this:
$this->uri->segment(3)
for more info http://ellislab.com/codeigniter/user-guide/libraries/uri.html
edit:
based on your url: clci.dev/account/profile/220 you would need $this->uri->segment(4)
Upvotes: 2