Passing multiple variables in URL using codeigniter

how to pass id in url in codeigniter
how to pass multiple data from controller to view in codeigniter
how to pass multiple parameters from view to controller in codeigniter
how to hide url parameters in codeigniter
codeigniter routes multiple parameters
argument in codeigniter
send data through url in codeigniter
how to pass id from view to controller in codeigniter

sorry to bother but I was hoping someone could help me out with a quite mundane issue that I am having within CI. I am able to send a variable via the URL using CI's examples eg:

http://localhost/project/main/getproduct/24

within the getproduct() method of my main controller I can get the variable sent 24, without an issue.

however I now want to pass two variables via the URL, but I have no idea how to do this or whether CodeIgniter will allow me to do this. could someone please show me how to pass 2 variables in CI and a method that can retrieve them I have tried:

http://localhost/project/main/getproduct/24/45

and then within my getproduct method:

public function getproduct($productID, $factoryID){
  .....
}

but I'm finding my method can get the first variable without an issue but not the second variable. Could anyone point me in the right direction please. Many thanks in advance.

You can use uri to retrieve values in your url

Here is an example

public function getproduct()
{
  $productID =  $this->uri->segment(3);
  $factoryID =  $this->uri->segment(4);
  // ProductID will be 25
  // Factory ID will be 45
}

Then you can just use the values as you please

How to pass multiple variables from URL request in Codeigniter , Sorry, I was a little bit confused by the wording of your question, but I think I understand what you are trying to talk about. First: Read the Docs� Passing data from controller to view in Codeigniter application is a great way of conforming to the standard MVC model. Check out this tutorial on the topic. Chat with us , powered by LiveChat

The accepted answer will work for this particular issue, but will not work if the url ever changes. To access multiple variables in your controller, simply add to the function definition.

http://localhost/project/main/getproduct/24/45

class Main extends CI_Controller {

    public function getproduct($productID = 0, $factoryID = 0)
    {
      // ProductID will be 25
      // Factory ID will be 45
    }
}

Reference: CodeIgniter User Guide

How can I pass multiple variables/values through the uri?, $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� Best Practice Tip. When constructing URL Variables to use in surveys, we recommend using all lowercase letters for the variable name. This will give you the most reliable results for using URL Variables within surveys, as well as passing them out of surveys using actions like the Webhook and URL Redirect.

You must set a route in config/routes.php to parse the items.

It looks like:

   $route["getproduct/(:any)/(:num)"]="main/changequestion/$1/$2"

Then i hope it will work.

Passing multiple parameters to function in URI, I want to pass two values to a controller from the view. Code: site_url('admin/ edit_user/'.$id.'/save'). and I want the function to accept it. right now� Pass multiple parameters in url using javascript in PHP Codeigniter. Multiple parameters pass: in Codeigniter web application you can pass single, twice and multiple parameters using JavaScript. You need to store value in a variable and pass variable into another location.

If someone else runs into this using CI3. In CodeIgniter 3 no special route is needed. Not sure if it also works on CI2 now.

You can access those URI segments using parameters just like that:

http://localhost/project/main/getproduct/24/45

public function getproduct($productID, $factoryID){
  .....
}

Pass parameter from controller to view file, In this example we are going to show you how to Pass parameter from controller to view file in CodeIgniter framework PHP. Here we using 2 files for pass� Passing data within the site using URL The same principle is used like above to send the data within the site using URL. A query sting can be formatted with a link or a form can be used with get method to pass variables between pages. Passing the data between the site through URL Like above data can be passed to different pages of sites using URL .

You can use uri to retrieve values in your url http://localhost/project/main/get_product/12/23

Here is an example

public function get_product(){
  $product_id =  $this->uri->segment(3);  // Product id will be 12
  $factory_id =  $this->uri->segment(4);  // Factory id will be 23

}

Then you can just use the values as you please

How to Pass Data From Controller to View in CodeIgniter, Passing data from controller to view in Codeigniter application is a great way of Pass array from controller to view; Load Multiple Views; Sort Views in Once you have created the controller, the URL for the view would be: Using this parameter returns data as a string instead of sending it to the browser. Once your URL is setup like that, you can do whatever you want to it with your JS. However , I strongly advise against this method because routing a class like this will pretty much render the rest of the application/site useless, unless this is your only controller/function (probably not the case) you have.

URL Helper — CodeIgniter 4.0.4 documentation, Code Modules � Managing your Applications � Handling Multiple Environments The URL Helper file contains functions that assist in working with URLs. file) will be added to the URL, as will any URI segments you pass to the function. of blindly trusting the HTTP_REFERER system variable, CodeIgniter will store� Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&". Read more about passing parameter through URL.

Passing Multiple Parameters Using Codeigniters Anchor Function , My problem was that I did not know how to pass multiple paremeters using Codeigniter's anchor function. The solution was quite simple in that all I had to do is� Quote:Please note: If you are using query strings you will have to build your own URLs, rather than utilizing the URL helpers (and other helpers that generate URLs, like some of the form helpers) as these are designed to work with segment based URLs.

CodeIgniter Passing Parameter, CodeIgniter Passing Parameter for beginners and professionals with examples on mvc, url, route url, models, file system, url, Model, View, Controller, database� Yes, this is pretty much it! Only im not using query strings. I had no idea you could pass multiple parameters via the url, im a codeigniter newbie and from the documentation i thought it was limited to one argument (ie controller/function/argument) Thanks for pointing me in the right direction, really appreciated it.

Comments
  • What does your getproduct method look like?
  • thanks this what spot on what I was looking for top notch upvotes for you!
  • I do not agree that this is the way to do it. You should not be reading the variables like that. CodeIgniter has a specific way to get that data without the need for two extra lines of code. See answer below stackoverflow.com/a/22774721/1084306
  • hey, do what Donovan says.
  • how would I then retrieve the variables in the method?
  • I have never had to to that - it's always just worked for me.
  • Try this: ellislab.com/codeigniter/user-guide/general/controllers.html . At Passing URI Segments to your Functions . Hope it helps . I think if you use more than 1 paramter when uri routing is active you can get them with uri->segment only. Getting them with uri segment It is basically the same thing.
  • I see... I've never used the URI routing feature. Thanks!
  • You do not HAVE to put a route in place to get these variables. It is already built into the controller to accept variables in the function.