Currently in my PHP-based applications I use a file, for instance services.php and call it via AJAX to return the appropriate data.
To call a certain method, I send a parameter in the GET. For instance services.php?action=read_article. From this point, it’ll hit a huge switch statement until it finds the appropriate case and returns the data I’m looking for.
Technically, everything works properly, but I can’t help but feel that it isn’t the right way to do it.
Is there a better way to implement web services in PHP?
The action switch is fine, if your using OOP you can have it call various methods to keep it small like..
Alternatively you could do what other frameworks do and map a URL into a method like..
Maps to class “Services” and method “Read” take a look at Codeigniter for how they do this.