0

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.

2
  • Why on earth would you want to use periods to separate URL arguments? Just stick with the accepted convention of either slash-delimited arguments, or the user of a query string. Commented Jul 26, 2014 at 18:30
  • If you explode /users/view/1.Jack with the var / u get a nice array with controller action then args then you explode the args with . and then you get a nice array with the args :P Commented Jul 29, 2014 at 17:06

1 Answer 1

2

There is. Take a look at call_user_func_array

call_user_func_array('function_name', $args);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.