【问题标题】:How to implement Luracast Restler 2.0 in IIS 7.5 with PHP 5+如何使用 PHP 5+ 在 IIS 7.5 中实现 Luracast Restler 2.0
【发布时间】:2012-02-22 11:35:43
【问题描述】:

我的 PHP 5 在 IIS 7.5 中运行良好,并且我已经在我的共享 linux 托管环境中使用 Restler.php 成功实现了一个 PHP api。

为了缩短开发时间,我决定将页面本地化到我的 Windows 环境中,但无法使用 Restler.php 让 api 与 IIS 中的 Rest 功能一起使用。

我搜索了帮助配置 IIS 的文档,甚至搜索了告诉我需要安装 URL 重写工具的语句,但找不到任何可以提供帮助的东西,我也无法让 API 返回任何内容,甚至“你好”世界”。

【问题讨论】:

  • 使用包含index.php Restler 的网址应该可以在 IIS 上开箱即用。我主要在Mac上。将在 IIS 上对其进行测试并在文档中包含步骤
  • 我已经完成了以下测试,不确定是否相关,但希望对您有所帮助。测试是 url:localhost/virtualdirectory/api。注释掉 index.php 中的所有行,并且 onyl 做了一个回应。这表明 PHP 正在 VD 中工作。
  • Echo 工作正常,所以我逐行取消注释 index.php require_once 'restler.php'; $r = new Restler(); $r->addAPIClass('Say'); $r->handle(); 在最后一行 handle();我收到此错误PHP Strict Standards: Only variables should be passed by reference in C:\Backup\Web\virtualdirectory\api\restler.php on line 2 PHP Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method DefaultResponse::__formatError() should not be called statically in C:\Backup\Web\virtualdirectory\api\restler.php on line 2
  • 下载了最新版本的 Luracast-Restler-v2.0.1-22-gc334e7e 并使用了普通的 restler.php 而不是最小的,现在得到错误:PHP Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method DefaultResponse::__formatError() should not be called statically in C:\Backup\Web\virtualdirectory\api\restler.php on line 293 这行显示为array($this->response, '__formatError'), $status_code, $message)
  • 请问您使用的 PHP 版本,我猜它可能低于 5.3。我刚刚在 IIS 7.5 和 PHP 5.3 上测试了 restler 示例,它们在 URL 中使用 index.php 渲染得很好。稍后我将为漂亮的 url 创建 Web.config 示例。 Restler 是为 PHP 5.3 编写的,并且应该使用战斗.php 文件向后兼容到 5.0。

标签: php api


【解决方案1】:

根据 cmets 和对该问题的跟进,很明显

  • Restler 2.1.4 已清除您提到的错误
  • 使用完整的 url(包括 index.php)可以正常工作
  • URL 重写不起作用

Restler 包含用于 URL 重写的 .htaccess 文件,这些文件是为 Apache 服务器编写的。

对于 IIS,您需要安装 URL Rewrite 模块,并使用重写规则创建一个 Web.config 文件。

This Guide 可以在此过程中为您提供帮助

【讨论】:

  • 是否有更直接的教程让 IIS 不能使用完整的 url?我在 restler 网站上看到 Luracast 想在下一个版本中集成它,但也许有人已经写了一些关于它的个人笔记?
【解决方案2】:

我在 Unix 和 Windows 上成功实现了 Restler。 Windows 实现的唯一区别是您需要在 URL 中包含 index.php。

因此,例如在 Unix 上,您将拥有:
http://www.something.com/service/controller/method/parm1/parm2

在 Windows 上,您将拥有:
http://www.something.com/service/index.php/controller/method/parm1/parm2

希望这会有所帮助。没有url重写或其他任何东西。它确实可以解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多