diff --git a/src/CoolApi/Core/Request.php b/src/CoolApi/Core/Request.php index abd75dd..eb06a1e 100644 --- a/src/CoolApi/Core/Request.php +++ b/src/CoolApi/Core/Request.php @@ -30,9 +30,11 @@ public function get($key = null) { // Retrieve POST variables public function post($key = null) { - if (is_null($key)) return $_POST; - if (isset($_POST[$key])) { - return $_POST[$key]; + $post = \CoolApi\Core\Utilities::getPost(); + + if (is_null($key)) return $post; + if (isset($post[$key])) { + return $post[$key]; } else { return false; } diff --git a/src/CoolApi/Core/Router.php b/src/CoolApi/Core/Router.php index 8e6a9b6..82dfe19 100644 --- a/src/CoolApi/Core/Router.php +++ b/src/CoolApi/Core/Router.php @@ -241,7 +241,7 @@ private function route ($route, $method) { // Do checks for baseUri if ($this->instance->config->baseUri !== '/') { - $route = ltrim($route, $this->instance->config->baseUri); + $route = str_replace($this->instance->config->baseUri, '', $route); } // If the route is empty, load the home route. diff --git a/src/CoolApi/Core/Utilities.php b/src/CoolApi/Core/Utilities.php index 42c6420..70e8d95 100644 --- a/src/CoolApi/Core/Utilities.php +++ b/src/CoolApi/Core/Utilities.php @@ -28,4 +28,13 @@ public static function merge_config (array &$array1, array &$array2) { print_r($merged); } + public static function getPost () { + if(!empty($_POST)) return $_POST; + + $post = json_decode(file_get_contents('php://input'), true); + if(json_last_error() == JSON_ERROR_NONE) return $post; + + return []; + } + }