1

I couldn't find an answer to this so I figured I could as well just ask.

First of all, here's little backstory so you get better understanding what I'm asking. I'm dealing with a legacy php project and new part of it will be separate from what already exists. Part of that is to create a REST api to transfer data between database and javascript.

Now what needs to be done: certain urls (everything with specific after root)(root/specific/class/method) will be redirected to index.php, which will sort out the request type, class and the method. Then use that part in interface class which would call out that class and its method.

So basically if the ajax request url was this: url/specific/user/all with type: GET, index.php would call out 'all' method from user class through the interface class.

Could someone please tell me how to achieve the index.php->interface->class part? I know how to sort out request type and url from the request but how do I take that information, pass it to interface class which then returns the answer from specific class and its method?

I know I didn't provide too much but if someone has experience with what I described above, please do tell.

Edit: little bit more information.

Ajax get request to: url/specific/user/all results in index.php getting these variables:

method: GET    
request: user   
key: all

And class user.php contains:

function all (){
}

How do I get from index.php to that specific function through interface class?

Rauno
  • 616
  • 8
  • 22
  • What do you mean by interface? – nerdlyist Sep 28 '16 at 11:17
  • something such as this: interface IRest { public function __construct($method, $path); public function run(); } – Rauno Sep 28 '16 at 11:23
  • If `request` has a valid value you can instantiate that class and perform the actions in `key` value if valid. Here is an example http://stackoverflow.com/questions/3112727/in-php-5-can-i-instantiate-a-class-dynamically – RST Sep 28 '16 at 11:23
  • I do not think you can interact with an interface in PHP. You would just want to call the class directly. http://stackoverflow.com/questions/2697399/interact-with-an-interface – nerdlyist Sep 28 '16 at 13:36

0 Answers0