【问题标题】:how can i use index.php instead of index.html in cordova?如何在科尔多瓦中使用 index.php 而不是 index.html?
【发布时间】:2014-09-01 21:26:11
【问题描述】:

我有一个开发的 index.php 文件,它在 Web 服务器中运行良好并与 MySQL 数据库连接。但现在我需要使用相同的 index.php 转换为应用程序并将其打包为设备文件格式( .apk、.ipx)。 我已经阅读here ,网络请求将在 xmlhttprequest 中进行,但我需要启动 index.php 而不是 index,html 文件。 我应该如何进行? 参考:http://phonegap.com/about/faq/

编辑: 我知道本机框架会查找 index,html,因为它是一个 webview,但需要解决此问题

编辑:我有一个安装了 phpmysql 的网络服务器来与应用程序通信。 我正在寻找的是加载 index,php 文件而不是 index.html (因为cordova 只显示 fot index,html 文件)。

【问题讨论】:

  • index.php 文件需要在外部服务器上运行,并且您的 javascript 应该使用 XMLHTTPRequest 来获取/发布数据到服务器。如果您希望应用程序执行所有操作,则需要使用 javascript 作为逻辑。
  • 基本上你不能在cordova中执行php代码。您需要一个支持 php 的网络服务器并尝试在网络服务器和您的应用程序之间进行通信

标签: php cordova phonegap-build


【解决方案1】:

你可以改变你的cordova项目根目录下的config.xml文件的内容来加载index.php而不是index.html

【讨论】:

  • 对于配置config.xml的新手,这个是怎么实现的呢?你能为你的答案提供一个sn-p吗?
【解决方案2】:

只需创建一个 index.html 文件,其中包含:

<html>
    <head>
        <meta HTTP-EQUIV="REFRESH" content="0; url="index.php">
    </head>
    <body>
    </body>
</html>

【讨论】:

    【解决方案3】:

    Cordova 仅支持 html 文件作为 config.xml 内容中应用的起始页。

    作为服务器端脚本的 PHP 需要托管在 Web 服务器上。

    要在 cordova 应用程序中默认打开 .php 页面,html 文件应重定向到 php 资源。

    在 index.html 代码中添加以下内容:

    <script>
        window.onload = function (e) {
            e.stopPropagation(true);
            window.location.href = "url containing the index.php resource file.";
        };
    </script>
    

    【讨论】:

      猜你喜欢
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 2012-12-21
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多