我不明白。我必须进行哪些设置才能让 REST-API 在我的 cloudcontrol URL 上运行。我制作了一个名为player的 Controller :
<?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.cloudcontrol.com/players/index 时收到 404
感谢您的帮助。
最佳答案
我需要更多信息来帮助您:
- 您是否根据本文档设置了根目录? https://github.com/cloudControl/buildpack-php#manually-setting-the-documentroot
- 如果是这样,请将测试文件放入根目录中并尝试通过浏览器打开它。
- 您部署了您的应用吗?
- 您的错误日志显示了什么内容?
关于php - 我正在尝试在 CloudControl 上使用 CodeIgniter 和 RestServer 实现 REST-API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597950/