I’m attempting to build a REST based web service that provides a currency conversion function.
Please note that I’m a beginner to OO PHP so this is all new and fairly confusing to me.
I want the service to receive URL’s encoded as:
http://www.mysite.com/conv/?amnt=7.15&from=GBP&to=USD
and I want it to return the results in the browser as an XML message. Error handing obviously needs to be catered for as well.
I’ve read numerous online tutorials and understand that I’ll be using GET for what I’m trying to achieve. What confuses me the most is how to structure my PHP files (in OO format) and how to actually output these results on the default index page.
What’s for you need OOP here?
Only if it’s a selfeducational project. I think you should use something like MVC pattern, there is a lot of documentation out there, simply (here) translate that model into OOP php classes, and than put it into some way like this:
Files, for easy explore should be named as *.class.php, if there any inheritance, it would be *.base.class.php, or *.module.class.php
Basic rules are:
In your index file there would be only 3-4 lines, where you construct you project root class (controller), and then inside your controller you handle request, then going to the module, which you requested, and then to the view, where your system outputs the result.
OOP is greatly covered in MVC frameworks such as Symfony, you should look there.