douxigai8757 2011-01-21 09:27
浏览 69
已采纳

从路由器获取计数控制器args?

ok im learning on how to make my own custom mvc system, so far i have created things like router and the controller.

example i have a controller profile class and an url www.helloworld.com/args1/args2/args3

class Profiles
{
    function index($args1,$args2)
    {
        echo var_dump($args1,$args2);
    }
}

heres are part of my router class that execute the method and the parms

        if (is_callable(array($controller,$method))) {
            call_user_func_array(array($controller, $method), $this->params);
        }

so far no error but somehow i need to give a 404. if the $this->params is different then the count(params) in the method that i call at call_user_func_array(array($controller, $method), $this->params);

ok what im thinking is if count get params not same as count params at the called class then 404, lets say i can count my $this->params it gave me a 3. but how about the params in the called class ? how can we count params in a called class by call_user_func_array?

Thanks for looking in

Adam Ramadhan

  • 写回答

3条回答 默认 最新

  • doucandiao9180 2011-01-21 09:35
    关注

    From what I know, there is no way of getting the parameter count for a method without using reflection. However, it's pretty simple and would look something like this:

    $reflector = new ReflectionClass('Profiles');
    $method = $reflector->getMethod('index');
    $parameters = $method->getParameters();
    
    printf('%s expects %d parameters', $method->name, count($parameters));
    

    Will yield

    index expects 2 parameter
    

    Note that reflection always comes with a cost. However, the performance implications of this should not be noticable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀