我用PHP&jQuery mobile,现在我正在寻找如何使用PhoneGap将此应用程序转换为apk文件。
有可能做到这一点吗?有什么教程可以帮助我学习如何做吗?
这是一种快速简单的方法,如果您扩展到更真实的生活中使用,效果会更好:
1-下载phonegap
2-使用本教程或使用phonegap构建您的第一个应用程序如何获得凝视
3-一旦你有了那就让我们去服务器端吧。。我们需要一个API,最简单的方法如下:
<?php
header('Access-Control-Allow-Origin: *');
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
if($_GET['nameofFunction'] == 'getHomepageContent'){
require_once('controllers/homeController.php');
$objHome = new homeController();
$jsonReturn = $objHome->gethome();
echo($jsonReturn);
}
?>
4-创建控制器来控制来自API的请求,例如这样的东西:
<?php
class homeController {
public function __contruct(){
}
public function gethome(){
//do what ever you need here, sql query, errors handling.. and return it
//back to the api.
//for example you could use something like this to return json array to the api
// without making much effort
if(mysql_num_rows($yourquery) > 0){
while($us = mysql_fetch_assoc($yourqueryResult)){
$output[]=$us;
$homeJsonResponse = json_encode($output);
}
return $homeJsonResponse;
}
}
?>
5-我们回到phonegap应用程序,现在确保您包含了所有需要的文件,jquery、jquerymobile、cordovajs、itouch、iscroll。。。。
6-创建将在加载时执行的函数,并对api进行ajax调用,这将返回json,只需使用jquery进行解析,就可以开始了。