使用CodeIgniter框架进行API调用

问题描述 投票:0回答:1

在邮递员中调用其余API时出错。请解决错误。给定的错误如下所示。

遇到了未被捕获的异常

类型:错误

消息:在布尔值上调用成员函数row()

文件名:C:\ xampp \ htdocs \ CodeIgniterRestApi \ application \ libraries \ REST_Controller.php

行号:935

回溯:

文件:C:\ xampp \ htdocs \ CodeIgniterRestApi \ application \ libraries \ REST_Controller.php行:469函数:_detect_api_key文件:C:\ xampp \ htdocs \ CodeIgniterRestApi \ index.php行:315函数:require_once

REST_Controller.php

if ( ! ($row = $this->rest->db->where($this->config->item('rest_key_column'), $key)->get($this->config->item('rest_keys_table'))->row()))
{
    $this->_allow = $this->_detect_api_key();
}
php rest api codeigniter
1个回答
0
投票

如果您没有正确配置Rest Server,则会出现此错误。

在你的情况下 - 你设置在你的rest.php配置文件(你会发现它unter /application/config/rest.php)关键$config['rest_enable_keys']true,但你没有创建必要的表。

如果你真的想要为你的休息服务使用密钥,你就要创建这个/那些表。这在相关的配置文件中有很好的记录。

你可以在你的文件或github上找到这些信息 - 看看here

创建代码

CREATE TABLE `keys` (
   `id` INT(11) NOT NULL AUTO_INCREMENT,
   `user_id` INT(11) NOT NULL,
   `key` VARCHAR(40) NOT NULL,
   `level` INT(2) NOT NULL,
   `ignore_limits` TINYINT(1) NOT NULL DEFAULT '0',
   `is_private_key` TINYINT(1)  NOT NULL DEFAULT '0',
   `ip_addresses` TEXT NULL DEFAULT NULL,
   `date_created` INT(11) NOT NULL,
   PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
© www.soinside.com 2019 - 2024. All rights reserved.