Skip to content

Commit 582e248

Browse files
author
Phil Sturgeon
committed
Now empty data sets will only bail on a 404 if no code is provided. Provide empty data and 200 and it will do exactly that. Suggested by CaioToOn.
1 parent 65a96c4 commit 582e248

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

application/libraries/REST_Controller.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,19 @@ public function _remap($object_called)
181181
* Takes pure data and optionally a status code, then creates the response
182182
*/
183183

184-
public function response($data = array(), $http_code = 200)
184+
public function response($data = array(), $http_code = null)
185185
{
186-
if (empty($data))
186+
// If data is empty and not code provide, error and bail
187+
if (empty($data) && $http_code === null)
187188
{
188189
$http_code = 404;
189190
}
190191

192+
// Otherwise (if no data but 200 provided) or some data, carry on camping!
191193
else
192194
{
195+
is_numeric($http_code) OR $http_code = 200;
196+
193197
// If the format method exists, call and return the output in that format
194198
if (method_exists($this, '_format_'.$this->request->format))
195199
{
@@ -637,7 +641,7 @@ private function _force_login($nonce = '')
637641
private function _force_loopable($data)
638642
{
639643
// Force it to be something useful
640-
if (!is_array($data) AND !is_object($data))
644+
if ( ! is_array($data) AND ! is_object($data))
641645
{
642646
$data = (array) $data;
643647
}

0 commit comments

Comments
 (0)