I have a php file that creates a json output. my problem is that i will need lots of functions that return json data. For example:
- i will need to fetch a list of all customers in a given db;
- I will need to fetch all vehicles from a given customer;
- i will need to fetch all data from a given vehicle
and so on. At this point i can have all this working if each function is in a separate php file. The complexity of this is only going to increase and i dont want to have lots of files cluttering the file system. Is there a way around this? any practical example would be appreciated
Sure. If you have one function for each type of action, like this:
Then create an array of valid actions:
Then we have a GET parameter called
action:We check to make sure it’s valid…
Then we call the correct function: