2012-09-23 129 views
-2

我不得不使用的PhoneGap(JS,AJAX)的Web移动应用程序的工作,我必须装备我的服务器,并在其上安装一个web服务执行某些功能和SQL请求并返回数据在XMLJSON格式到我的应用程序。 但是,当我搜索我们如何创建web服务(使用php)我看到,我们必须创建很多包含搜索方法等方法的文件... 一位朋友告诉我,可以轻松创建一个强大的使用为此创建的特定框架的webservice。 你能推荐给我一些框架(它使用PHP作为princiapl语言) 谢谢:)web服务框架

+0

b.t.w.有什么理由避免REST? –

+0

谢谢:)完全没有 – Copernic

+0

为什么你认为他想避免REST? – ddinchev

回答

1

我不知道你是否想要使用框架。因为它只是一个extern API(不是引用的站点),所以不需要重写URL。使用框架会减慢你的速度。 我认为最好的做法是按专题创建一个文件并创建一个“内核”文件。

像这样:

//file : Kernel.php 
//one URL will be build as mysite.com?action=action&method=method&othervars... 
if(!isset($_GET['action'])){ 
    header('403: forbidden'); 
    exit(); 
} 

try{ 
    $controller = $_GET['action'].'Controller'; 
    if(is_file($controller.'.php'){ 
     $contoller = new $controller(); 
     $method = "execute".$_GET['method']; 
     if(is_callable(array($controller,$method)){ 
     $controller->$method(); 
     exit(); 
     }else{ 
     header('404: Not Found'); 
     exit(); 
     } 
} 
+0

非常感谢你:) – Copernic