doubu1853 2014-09-29 11:21
浏览 25
已采纳

如何编写一个将数组作为URL参数发送的控制器?

In some MVC platforms, a controller method accepts an URL's contents as forward-slash separated list of elements, received as parameters, e.g.

 site.com/controller/method/var1/var2

has associated controller:

class Controller

  function method(var1, var2){
  }
}

But how can I achieve this coding? I wish to start with an array and send a parameterized list to a function, i.e.

$args = array("one"=>"cheese","two"=>"eggs");

php_function("myfunction",$args);

Within myfunction, I would have

function myfunction($one, $two){
}

I know about func_get_args for accepting an unknown number of arguments. user_call_func is useful except

user_call_func("myfunction",$args);

...results in the first parameter containing an array of arguments, no difference to func_get_args called from within the function.

extract doesn't work either as I need to receive the array as a variable inside the function.

  • 写回答

2条回答 默认 最新

  • dt3674 2014-09-29 11:28
    关注

    I've managed to create your desired with the following.

    class BootStrap {
    
    private $controller = 'NameOfIle.php';
    private $method = 'function()';
    private $params = array('sdfds' => 'dsfdsf', 'sdfdsfsdfdsfsd' => 'sdfdsfds');
    
    
    public function __construct() {
      call_user_func_array(array($this->controller, $this->method), $this->params);
     }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接