CodeIgniter Forums
Controller routing question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Controller routing question (/showthread.php?tid=12290)



Controller routing question - El Forum - 10-13-2008

[eluser]blasto333[/eluser]
lets say I have a url like this:

http://localhost/index.php/customers/edit/2/random1223940682488

In my customers controller....

Code:
function edit($customer_id)
{
     echo $customer_id;
}

How come codeigniter does not complain that it cannot find a function with signature...
function edit ($customer_id,$randomstring)

I am kind of glad it doesn't, but is this a recommend practice.


The reason I am passing a random string is so ajax does not cache requests.


Controller routing question - El Forum - 10-13-2008

[eluser]Matrices[/eluser]
You can use your uri segments to pass information not only to a controller, but to a view file as well (or any file for that matter).

By calling the uri class, you can grab a variable stored in your url instead of doing something else like passing it through a form. I'm not quite sure what your question is, but I hope this clears up why CI doesn't throw an error when you don't assign a uri segment to be passed through a controller function.

For more info on uri segments go here.


Controller routing question - El Forum - 10-13-2008

[eluser]blasto333[/eluser]
Using this example again http://localhost/index.php/customers/edit/2/random1223940682488

I would thing codeigniter would require a function with 2 parameters.

function edit ($customer_id,$randomstring)
{

}

But it works if I just have a function with 1 parameter, which I thought was strange behavior.


Controller routing question - El Forum - 10-13-2008

[eluser]Matrices[/eluser]
A CI function only requires as many variables as you assign to it. The rest of your url, "random1223940682488" can be ignored or used by your own code if you need it. This is one of the features that makes CI easy to use.


Controller routing question - El Forum - 10-13-2008

[eluser]blasto333[/eluser]
I like it!


Controller routing question - El Forum - 10-13-2008

[eluser]Colin Williams[/eluser]
In PHP, and many other scripting and programming languages, you can throw as many arguments at a function that you want. Your only requirement is that you at least pass the arguments it needs. So, CI will always call $controller->$method($param1, $param2) (for example) provided there is a param1 and param2 (URI params).

http://php.net/functions