Reputation: 2275
I'm writing my own framework (for learning) and I am at the stage where I want to pass parameters to a method. at the moment I'm achieving this via:
$params = array_slice($url, 1);
$class->{$method[1]}($params);
then in the method of the class I have $params = func_get_arg(0);
This works but is not ideal, I notice that in Codeigniter you can call
http://domain.com/controller/method/p1/p2/p3
...
then in the method you get these via
method($p1, $p2, $p3){}
This is what I would prefer. How would I set this up?
ps: my classes all extend a base class
Upvotes: 2
Views: 73
Reputation: 2016
Did you try to pass an array that contains all your paramters instead of trying to pass all parameters one by one ?
Upvotes: 0
Reputation: 59699
Underneath the hood, I'm betting CI uses call_user_func_array()
to do this:
call_user_func_array( array( $class, $method[1]), $params);
Now, depending on the number of parameters in the array, you could have methods like you hinted at:
method($p1, $p2, $p3){}
Assuming there were 3 parameters in the $params
array.
Upvotes: 1
Reputation: 2898
Try this:
call_user_func_array( array( $class, $method ), $params );
Upvotes: 0