Created
August 2, 2012 19:49
-
-
Save danmatthews/3240064 to your computer and use it in GitHub Desktop.
Solution to doing some processing for every method of FuelPHP REST controller.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ExampleRestController extends Controller_Rest { | |
/** | |
* Make sure the router method has the same method signature as the parent::router declaration. | |
* @see fuel/core/classes/controller/rest.php | |
*/ | |
public function router($method, array $params) { | |
// Run a method that validates the provided API key. | |
if (!static::validateMyAPIKey()) | |
{ | |
// If it has not passed validation return a FuelPHP Response object. | |
$response = Response::forge(Format::forge(array('Error' => 'Failed to authenticate you'))->to_json(), 401)->set_header('Content-Type', 'application.json'); | |
return $response; | |
} | |
// The API key is valid, Route the request! | |
parent::router($method, $params); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment