php - 我正在尝试在 CloudControl 上使用 CodeIgniter 和 RestServer 实现 REST-API

标签 php .htaccess codeigniter rest cloudcontrol

我不明白。我必须进行哪些设置才能让 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

感谢您的帮助。

最佳答案

我需要更多信息来帮助您:

  1. 您是否根据本文档设置了根目录? https://github.com/cloudControl/buildpack-php#manually-setting-the-documentroot
  2. 如果是这样,请将测试文件放入根目录中并尝试通过浏览器打开它。
  3. 您部署了您的应用吗?
  4. 您的错误日志显示了什么内容?

关于php - 我正在尝试在 CloudControl 上使用 CodeIgniter 和 RestServer 实现 REST-API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597950/

相关文章:

php - CakePHP 中 SSL 的最佳实践

apache - .htaccess 如果文件存在则重定向,否则传递

php - 如何在codeigniter数据库中查询

php - redirect() 函数不适用于 CodeIgniter 中的外部 URL

php - 如何在 Mysql 中使用 like 运算符搜索法语单词?

php - 在 drupal 7.0 中页面加载时将数据库值保存在文本字段中

php - 什么是 "Request Headers From Upload Stream"

regex - 需要帮助重写规则以使 url 干净且 seo 友好?

php - CodeIgniter - 从本地主机连接时出现数据库错误

Php-使用 post 方法在 Mysql 表中没有写入任何内容