Reputation: 320
I am not getting it. What settings do I have to make to get the REST-API running on my cloudcontrol URL. I made a controller named 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
}
}
This I put in the config.php:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;
$config['index_page'] = '';
I am using the .htaccess from MobileBoilerplate and changed RewriteBase like this
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
</IfModule>
Do I have to make special settings for the routing? How can I do that on CloudControl? Is there another mistake? I am getting 404 when I try to access myproject.cloudcontrolled.com/players/index
Thanks for any help.
Upvotes: 2
Views: 528
Reputation: 415
I would need some more information to help you:
Upvotes: 2