turn URL route into funciton arguments php mvc

后端 未结 3 1861
野的像风
野的像风 2020-12-19 23:13

I\'m writing a custom MVC framework for a PHP project and everything is great until it comes to getting arguments from the URL route. I\'m stuck on passing parts of the URL

3条回答
  •  春和景丽
    2020-12-20 00:02

    The easiest way to handle this is to use the call_user_func_array() function. You would use it as follows:

    call_user_func_array(array($controller, $method), $params);
    

    $controller would be the controller object you have already created, and $method would be the controller's method. Then $params is an array of the parameters collected from the URI. You would just need to take out the controller/method portion of the URI.

    You could also do this using Reflection, but this typically is slower than using the above method.

提交回复
热议问题