我正在使用Phil Sturgeon和Chris Kacerguis Restful服务器(访问https://github.com/chriskacerguis/codeigniter-restserver)并对使用API KEYS有一般性问题.我是API和概念的新手.
KEYS如何工作?有一个名为KEYS的表定义如下:
| Default table schema:
| 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;
Run Code Online (Sandbox Code Playgroud)
类中有一些名为KEYS的方法如下:
index_put() // key created. builds a new …Run Code Online (Sandbox Code Playgroud) 这是一个简单的代码snipplet,但这只是挂起和反应迟钝.
$httpClient = new GuzzleHttp\Client(); // version 6.x
$headers = ['X-API-KEY' => '123456'];
$request = $httpClient->request('GET', 'http://localhost:8000/BlogApiV1/BlogApi/blogs/', $headers);
$response = $client->send($request, ['timeout' => 2]);
echo $request->getStatusCode();
echo $request->getHeader('content-type');
echo $request->getBody();
die();
Run Code Online (Sandbox Code Playgroud)
任何指针都非常赞赏.当我使用我的用户名和密码尝试使用github api时,我得到了200响应和大量信息.
我正在使用Phil Sturgeon的REST服务器,CI3和POSTMAN进行调试.我发送了一个PUT以下信息,但是,我没有收到预期的错误消息.
这是我的form_validation.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'student_put' => array(
array('field' => 'email_address', 'label' => 'email_address', 'rules' => 'trim|required|valid_email'),
array('field' => 'password', 'label' => 'password', 'rules' => 'trim|required|min_length[8]|max_length[16]'),
array('field' => 'first_name', 'label' => 'first_name', 'rules' => 'trim|required|max_length[50]'),
array('field' => 'last_name', 'label' => 'last_name', 'rules' => 'trim|required|max_length[50]'),
array('field' => 'phone_number', 'label' => 'phone_number', 'rules' => 'trim|required|alpha_dash'),
)
);
?>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器Api.php中的方法:
function student_put(){
$this->form_validation->set_data($this->put());
// these are the rules set in config/form_validation.php
if …Run Code Online (Sandbox Code Playgroud) 在 Chrome 开发者工具中,图例完美地显示在桌面、平板电脑和移动设备的 Mapbox 地图之上。这是看起来的样子。它显示半透明的水平图例。
但如果我实际使用 iPhone,图例将无法正确显示。它变成垂直的并且所有格式似乎都丢失了。
这是我的地图框控件:
// Control implemented as ES6 class
class fs_legend_control {
onAdd(map) {
var fs_legend_control_html = ' \
<div class="my-legend"> \
<div class="legend-title">Piste Difficulty Legend</div> \
<div class="legend-scale"> \
<ul class="legend-labels"> \
<li><span style="background:#339933;"></span>Novice</li> \
<li><span style="background:#097CCB;"></span>Easy</li> \
<li><span style="background:#ED151F;"></span>Intermed\'</li> \
<li><span style="background:#000000;"></span>Advanced</li> \
<li><span style="background:#ffa502;"></span>Expert</li> \
<li><span style="background:#ffff01;"></span>Freeride</li> \
<li><span style="background:#ffc0cb;"></span>Unrated</li> \
</ul> \
</div> \
<div class="legend-source"> <a href="https://www.example.com/pistes/">About Piste Difficulty</a></div> \
</div> \
';
this._map = map;
this._container = document.createElement('div');
this._container.className …Run Code Online (Sandbox Code Playgroud) 我本来要更新数据库,但收到错误“没有要更新的数据”。这是我的脚本;
我创建了一个简单的切换来更新数据库。切换使用户处于活动状态 (is_active=1) 或非活动状态 (is_active=0)。我遇到的问题是,虽然对象从 1 更改为 0 或 0 更改为 1,但当我将其传递给模型时,它会返回错误“没有要更新的数据”。方法如下;
命名空间 App\Controllers\Admin;
使用应用程序\实体\用户;
class Users 扩展了 \App\Controllers\BaseController { private $model;
public function __construct()
{
$this->model = new \App\Models\UserModel;
}
public function toggle_user_is_active($id)
{
$users = $this->model->where('id', $id)->first(); // get the record
// if the current user is ACTIVE, then set it to DEACTIVE
if ($users->is_active == 1) {
$users->is_active = 0;
$this->model->save($users)); // gives an error, nothing to update
return redirect()->to('/Admin/Users/index')
->with('info', 'Success - User deactivated');
} else …Run Code Online (Sandbox Code Playgroud)