Reputation: 190
I am thinking of making a PHP framework, now I know roughly how MVC works and I have watched some tutorials on making basic MVC projects.
I understand that the address is example.com/controller/action/arg1/arg2/arg3 now I would like the URL to look like example.com/controller/action/arg1.arg2.arg3. I can just implode the args to get each arg in an array.
However i'm not sure how to call the action with those args because you cant put a foreach statement inside the args of calling a function so would I need a long list of calls for the actions with different amounts of args like
if(count($args) == 1){call($args[0]);}
if(count($args) == 2){call($args[0], $args[1]);}
if(count($args) == 3){call($args[0], $args[1], $args[2]);}
I'm guessing there is a much cleaner way of doing it.
Upvotes: 0
Views: 64
Reputation: 11806
There is. Take a look at call_user_func_array
call_user_func_array('function_name', $args);
Upvotes: 2