【问题标题】:while running SimpleAuth.php it gives fatal error in restler在运行 SimpleAuth.php 时,它在 restler 中给出了致命错误
【发布时间】:2013-02-09 11:26:18
【问题描述】:

我正在运行以下网址并尝试运行 SimpleAuth.php

http://localhost/restler/public/examples/nof/SimpleAuth.php 它给了

Fatal error: Interface 'Luracast\Restler\iAuthenticate' not found in C:\wamp\www\Restler\public\examples\nof\SimpleAuth.php on line 5

SimpleAuth.php 的内容

use Luracast\Restler\iAuthenticate;

class SimpleAuth implements iAuthenticate
{
    const KEY = 'rEsTlEr2';

    function __isAllowed()
    {
        return isset($_GET['key']) && $_GET['key'] == SimpleAuth::KEY ? TRUE : FALSE;
    }

    function key()
    {
        return SimpleAuth::KEY;
    }
}

iAuthenticate.php

namespace Luracast\Restler;

interface iAuthenticate extends iFilter{  }

【问题讨论】:

  • 请在 .htaccess 文件中启用错误显示

标签: php restler


【解决方案1】:

看起来你直接调用了你不应该做的`C:\wamp\www\Restler\public\examples\nof\SimpleAuth.php',除非你包含restler.php,否则它不会工作

确保您的 index.php 正确包含 restler.php,一旦这样做,我们的自动加载器应该能够加载 'Luracast\Restler\iAuthenticate' 就好了。

您不应该尝试自己创建 restler api 类。

【讨论】:

  • 好的,还有一件事我如何通过查询字符串传递值,而没有 /add/4/4 和 add?n1=4&n2=4
【解决方案2】:

你是否正确定义了命名空间 iAuthenticate 是否有效且已定义

你是在自动加载吗 命名空间 Luracast\Restler\iAuthenticate 与否?

【讨论】:

  • 是的,它定义正确。但我不确定自动加载 bcoz 它在框架中完成。我添加了 iAuthenticate.php .pls varify 并帮助我
【解决方案3】:

在我的测试中它运行良好

看看这个

命名空间 Luracast\Restler; 接口 iAuthenticate { } 使用 Luracast\Restler\iAuthenticate as ia; 类 SimpleAuth 实现 ia { 常量键 = 'rEsTlEr2'; 函数 __isAllowed() { 返回 isset($_GET['key']) && $_GET['key'] == SimpleAuth::KEY ?真假; } 功能键(){ 返回 SimpleAuth::KEY; } }

【讨论】:

  • 你能告诉我我做错了吗?
  • 上面已经提到过,或者如果 iFilter 是全局的,则将 interface iAuthenticate extends iFilter{ } 替换为 interface iAuthenticate extends \iFilter{ }
  • 不,它不是全局的,它只是另一个具有一个方法函数的接口 __isAllowed() {}
猜你喜欢
  • 2019-02-03
  • 2012-06-16
  • 2022-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多