我在MVC结构中使用 现在当我使用它时: p>
有没有办法发送全部 作为单个数组的类方法的参数? 不知道是否有任何参数可以开始,如果有,那就不知道有多少参数。 我不想这样做: p>
我希望这样做: p>
call_user_func_array code>指向控制器和方法并通过 URL的参数: p>
//此时,$ url是一个只有参数的数组
$ this-> params = $ url? array_values($ url):[]; //
call_user_func_array([$ this-> controller,$ this-> method],$ this-> params);
code> pre>
class Home extends Controller {
公共函数索引( $ param1 = null,$ param2 = null){//丑陋......
// ..继续
code> pre>
公共函数索引($ param1 = null,$ param2 = null,$ param3 = null,$ param4 = null){\ n code> pre>
公共函数索引($ params){
if (isset($ params [0])){
code> pre>
div>
I am using call_user_func_array
in an MVC structure to point to a controller and method and pass the parameters of the URL:
// At this point, $url is an array with nothing but parameters
$this->params = $url ? array_values($url) : []; //
call_user_func_array([$this->controller, $this->method], $this->params);
Now when I use this:
class Home extends Controller {
public function index($param1=null, $param2=null) { // Ugly...
// .. continue
Is there any way to send all the parameters to the class method as one single array? There's no telling if there are any parameters to begin with, and if there are, there's no telling how many. I don't want to have to do:
public function index($param1=null, $param2=null, $param3=null, $param4=null) {
I'm looking to do:
public function index($params) {
if (isset($params[0])) {