Welcome Guest, Not a member yet? Register   Sign In
Controller routing question
#1

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

http://localhost/index.php/customers/edi...3940682488

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.
#2

[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.
#3

[eluser]blasto333[/eluser]
Using this example again http://localhost/index.php/customers/edi...3940682488

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.
#4

[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.
#5

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB