【问题标题】:How to have a "home" page when all is routed through index.php当所有都通过 index.php 路由时,如何拥有一个“主页”页面
【发布时间】:2014-11-15 19:46:58
【问题描述】:

我正在为如何将 Restler 与网站集成而苦苦挣扎。如果我们举一个最简单的例子:hello world,它要求.htaccess 通过index.php 路由所有内容。但是,如果我的主页需要驻留在那里怎么办?例如,我怎么能简单地:

  1. 当用户进入我的网站时,有一个“主页”页面
  2. 要继续,也许此页面上有一个表单,他们可以提交给我在 restler 中的班级

文档中有一个表单示例,但它非常复杂,需要使用其他框架。我想从简单开始。目前,如果我按照 hello world 示例但选择进入我的站点主页 mysite.org/index.php 我会收到错误

"{
    "error": {
      "code": 404,
      "message": "Not Found"
    },
    "debug": {
      "source": "Routes.php:436 at route stage",
      "stages": {
         "success": [ "get" ],
         "failure": [ "route", "negotiate", "message" ]
      }
    }
}".

如何使 index.php 成为访问者可以使用的东西?

【问题讨论】:

    标签: php restler


    【解决方案1】:

    创建一个类以映射到网站的根目录。比如说 Home 类

    class Home {
       public function index(){
           return "The content for root";
       }
    }
    

    然后在添加 Home 类时将其映射到根目录

    $r = new Restler();
    $r->addAPIClass('Home',''); //second parameter is the path to map it to where blank means root
    ...
    

    现在您的 api root 将回复 "The content for root"

    【讨论】:

      【解决方案2】:

      我总是将 restler 相关的东西安装到我网站的一个名为 API 的子目录中,这就是 .htaccess 进行重写的地方。这样我的网站仍然是一个“普通”的网站,然后所有的 API 东西都存在于它自己的目录中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-09
        • 2019-07-06
        • 2012-03-30
        • 1970-01-01
        相关资源
        最近更新 更多