1. 测试环境
系统: windows+apache+php
框架: ThinkPHP3.1.3+TPM
IP: 192.168.0.109
2. 新建一普通web项目:
index.php 内容:
<?php
//定义项目名称和路径
define('APP_NAME', 'APP');
define('APP_PATH', './APP/');
// 加载框架入口文件
require( "./ThinkPHP/ThinkPHP.php");
?>文件目录结构:
3. 增加 ./APP/lib/Action/IndexAction.class.php 文件:
<?php
class IndexAction extends Action {
public function index(){
$hello = 'Hello World';
$this->assign('hello',$hello);
$this->display();
}
}
?>增加 ./APP/Tpl/Index/index.html 模版文件 。这个模版文件,后面如果不使用单独的mobile模版的话,这个文件等下要被覆盖。
{$hello},这是web模版。4. 下载TPM, 将下载的文件中,4.1 将SwitchMobileTplBehavior.class.php 复制到项目目录下 Lib/Behavior 目录下,
4.2 将TemplateMobile.class.php 文件复制到 ThinkPHP/Extend/Driver/Template 下。
4.3 如果不使用Mobile独立模版,将Tpl目录下的文件复制到你的项目文件夹下Tpl目录中。 这样Index/index.html 会提示是否覆盖,选择否。
5. 修改 ./APP/Conf/config.php ,添加下面内容,开启layout,
<?php
return array(
'LAYOUT_ON'=>true
);
?>6. 在项目的Conf文件夹下建立tags.php ,代码为:<?php
return array(
'action_begin'=>array('SwitchMobileTpl')
);
?>7. 编辑器打开Tpl/index.html文件,注意不是Tpl/Index/index.html修改代码。因为默认是Index/index操作,所以下面直接写,我的地址如下,请自行将网址修改为你项目的真实访问地址:TPM.run("http://192.168.0.109/index.php"); 8. 打包工作,官方打包后,提示没有index.html模版,所以这里采用phonegap在线打包。步骤:8.1 把Tpl目录下的build.php去除后,用压缩软件压成一个zip包,

8.2 把zip包上传至phonegap,

8.3 下载刚才生成的APK后,安装到手机

8.4 在手机上打开刚才安装的APP,PGBuildApp-debug.apk,

8.5 更改 ./APP/lib/Action/IndexAction.class.php 文件:
<?php
class IndexAction extends Action {
public function index(){
$hello = '张三';
$this->assign('hello',$hello);
$this->display();
}
}
?>然后访问手机APP,如下:
进行到上面,基本完工。设置mobile独立模版没测试成功,有空再测试。
最佳答案