【问题标题】:Authenticate Against Database with Phil Sturgeon’s Rest-Server使用 Phil Sturgeon 的 Rest-Server 对数据库进行身份验证
【发布时间】:2011-08-27 10:44:22
【问题描述】:

我正在尝试修改 Phil Sturgeon 的 rest-server 以针对 ion-auth 进行身份验证。我将 _check_login 更改为:

private function _check_login($username = '', $password = NULL)
{
    if (empty($username))
    {
        return FALSE;
    }

    $this->rest->db = $this->load->database('default', TRUE);
    $sql = 'SELECT api_key FROM users WHERE email = ?';
    $query = $this->rest->db->query($sql, urldecode($username));

    if ($query->num_rows() > 0) {
        $user = $query->row_array();
    } else {
        return FALSE;
    }

    // If actually NULL (not empty string) then do not check it
    if ($password !== NULL AND $user['api_key'] != $password)
    {
        return FALSE;
    }

    //return TRUE;
    return $user['api_key'];
}

我的第一个问题是我需要做什么:

$this->rest->db = $this->load->database('default', TRUE);

在我看来 $this->rest->db 应该已经可以访问了,因为它是在构造函数中设置的,但是我得到一个错误,说如果我不添加_check_login 中的 load->database() 行,如上。注意:我删除了构造函数中的 if 语句,该语句仅在启用键或日志记录时才初始化数据库连接,因此这不应该是问题。

我认为我的第二个问题是问题 1 的结果。无论如何,在对 REST_Controller 进行更改后,我的 REST 控制器中的模型不再工作。我得到的错误是:

遇到了 PHP 错误

严重性:通知

消息:未定义的属性:用户::$db

文件名:core/Model.php

行号:50

当我调用我的一个模型中的方法时,这似乎正在发生。

希望这些信息足以帮助查明问题。关于我可能做错了什么的任何想法?谢谢!

【问题讨论】:

    标签: php api authentication codeigniter rest


    【解决方案1】:

    我相信 db 类位于 $this->db。你试过吗?

    编辑:啊,$this->rest->db 似乎也是 $this->db 的别名。

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2012-10-05
      • 2013-06-27
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      • 2018-09-11
      相关资源
      最近更新 更多