I am trying to create a little MVC framework for myself and am using a url structure similar to: http://www.example.com/className/methodName/var1/var2/var3. I want to make it able to accomodate for any number of variables.
I have all of the information how I need it, except for the /var1/var2/var3 part. Currently I have it in an array exploded() upon the "/", so: var[0] = "var1",var[1] = "var2",var[2] = "var3"
Since the method which will be called will be unknown and each method can require a different amount parameters I want to figure out a way to be able to pass the parameters as:
$controller->$function($var1, $var2, $var3);
rather than
$controller->$function($var);
I realize I can string together a comma delimited variable such as $var1, $var2, $var3 and use eval() to do what I want, but I am wondering if there is a better way to go about it. I would rather not use eval() for this as it will be using user submitted data.
Worst case scenario, I figure I would just try to cleanse the data before the eval, but I'd still like to avoid it.
One other potential Idea I had was to use a foreach() and loop through each element inside of the the method call. But even that seems a little messy to me.
On a side note, is the standard way to pass a variable amount of parameters to group them together in an array and pass in a single parameter?
If anyone knows of a more elegant way to do this, I would really appreciate it.