call_user_func_array 页面在 PHP 框架中的服务方式是什么?
Is call_user_func_array the way a page is served in PHP frameworks?
自己写了一个小框架,正在研究别人的。它们很大,所以我还在努力掌握它们的设计。
当用户调用控制器或路由器时,call_user_func_array
页面是"handed off"渲染器的典型方式吗?
我倾向于看到这种类型的 thing,这就是我在我的作品中所做的。看起来这就是它在 Codeigniter 中所做的,但我不确定。
if ((int)method_exists($controller, $action)) {
call_user_func_array(array($dispatch,$action),$queryString);
} else {
/* Error Generation Code Here */
}
我在 CodeIgniter 中看到了这个:
// Execute the callback using the values in matches as its parameters.
$val = call_user_func_array($val, $matches);
call_user_func_array()
函数用于当你不知道你提前调用的函数时。这就是为什么大多数时候,里面的参数都是变量。
如果您知道要调用什么函数,请始终手动调用它,否则,请使用此 php 内置函数。
您应该查看 PHP 文档:http://php.net/manual/en/function.call-user-func-array.php
另一个堆栈溢出问题也回答了这个问题:
PHP call_user_func vs. just calling function
自己写了一个小框架,正在研究别人的。它们很大,所以我还在努力掌握它们的设计。
当用户调用控制器或路由器时,call_user_func_array
页面是"handed off"渲染器的典型方式吗?
我倾向于看到这种类型的 thing,这就是我在我的作品中所做的。看起来这就是它在 Codeigniter 中所做的,但我不确定。
if ((int)method_exists($controller, $action)) {
call_user_func_array(array($dispatch,$action),$queryString);
} else {
/* Error Generation Code Here */
}
我在 CodeIgniter 中看到了这个:
// Execute the callback using the values in matches as its parameters.
$val = call_user_func_array($val, $matches);
call_user_func_array()
函数用于当你不知道你提前调用的函数时。这就是为什么大多数时候,里面的参数都是变量。
如果您知道要调用什么函数,请始终手动调用它,否则,请使用此 php 内置函数。
您应该查看 PHP 文档:http://php.net/manual/en/function.call-user-func-array.php
另一个堆栈溢出问题也回答了这个问题: PHP call_user_func vs. just calling function