Welcome Guest, Not a member yet? Register   Sign In
How can I pass multiple variables/values through the uri?
#1

I've been using the uri to pass multiple values to my model with something like...


Code:
<?php echo anchor("main/request_details/$r->submitTime", 'View'); ?>


and using it to make a query in the model with...


Code:
$this->db->where('submitTime', $this->uri->segment(3));


but now I need to pass 2 values through the url. Is there a way to do this or am I going about this the wrong way perhaps? Thanks
Reply
#2

You can just add a new segment like you are when adding the 3rd.

Parameters are automatically passed to the controller/method as arguments, like
<?php echo anchor("main/request_details/$r->submitTime/anotherParameter", 'View'); ?>

You just need to capture them in the method and would be available like:
PHP Code:
function request_details($submitTime ''$anotherParameter ''//assign the variables being passed, AND set a default value
{
  if ( ! empty(
$submitTime))
  {
    
//submitTime was passed, do something with it
  
}
  
//instead of $submitTime = $this->uri->segment(3);

  
if ( ! empty($anotherParameter))
  {
    
//do something with $anotherParameter
  
}
  
//instead of $anotherParameter = $this->uri->segment(4);


By setting the default values in the method, you can use the controller for:
http://yoursite.com/main/request_details
http://yoursite.com/main/request_details/{submit_time}
http://yoursite.com/main/request_details..._parameter}
Reply
#3

Thanks! thats exactly what I'm looking for
Reply
#4

(This post was last modified: 04-14-2015, 12:13 PM by Muzikant.)

Read Passing URI Segments to your methods.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB