CodeIgniter Rest API的自定义错误消息

时间:2016-06-28 16:45:03

标签: php codeigniter api rest

您好我正在使用https://github.com/chriskacerguis/codeigniter-restserver/blob/master/application/libraries/REST_Controller.php使用CodeIgniter进行REST API构建。

在_detect_api_key()函数中,他只检查给定的Api Key是否与存储在表中的Api Key匹配。我修改了一下这个方法,不仅检查api密钥是否匹配,还检查用户是否激活。对于这两种情况,我都会收到无效的API密钥消息。

如何将消息设置为“您正在使用的API密钥未激活”或类似内容?

我用于错误消息的文件是:

/*
 * English language
 */

$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';

并且在_detect_api_key方法中没有提到有关错误消息的任何内容只返回false:

 if ( !($row = $this->rest->db->where($this->config->item('rest_key_column'), $key)->get($this->config->item('rest_keys_table'))->row()) ||   $isactive[0]->activated === 'no' )
            {
                return FALSE;
            }

我补充说:

$isactive[0]->activated === 'no'

有什么想法吗?

0 个答案:

没有答案