我不明白。我必须进行哪些设置才能在我的 cloudcontrol URL 上运行 REST-API。我制作了一个名为 player 的控制器:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH'.libraries/REST_Controller.php');
class Players extends REST_Controller {
function index() {
echo 'It works';
}
public function players_get() {
$this->response($this->db->select('playerName')->result());
}
public function player_get() {
if(!$this->get('playerName')) {
$this->response(NULL, 400);
}
$playerName = $this->input->get('playerName');
$this->response($this->db
->select('playerName')
->from('players')
->where('playerName', $playerName)
->get()
);
}
public function player_post() {
$playerName = $this->input->post('playerName');
$password = $this->input->post('password');
$player = array(
'playerName' => $playerName,
'password' => $password
);
// INSERT INTO 'players' (playerName, password) VALUES ($playerName, $password);
$this->db->insert('players', $player);
// On success, send back array with data
$this->response($player, 201); // Send an HTTP 201 Created
// On fail, send empty array
$this->response(array()); // HTTP 404 Not Found
}
}
这是我放在 config.php 中的:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
$config['index_page'] = '';
我正在使用 MobileBoilerplate 中的 .htaccess 并像这样更改了 RewriteBase
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
</IfModule>
我必须对路由进行特殊设置吗?如何在 CloudControl 上做到这一点?是不是还有一个错误?当我尝试访问 myproject.cloudcontrolled.com/players/index 时收到 404
谢谢你的帮助。