-
-
Save tarnfeld/836775 to your computer and use it in GitHub Desktop.
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 Controller_Blog extends Controller { | |
/** | |
* This is a simple example, the class does not exist. There are much more | |
* things you would be able to do, this is just an example. | |
* | |
* Yes, I know this is all (kind of) currently possible, but this encapsulates | |
* the response and allows for nice things like advanced response caching. | |
*/ | |
/** | |
* Here is what your dispatch class method thing could look something like: | |
* | |
* $instance_of_controller->dispatch_however_you_do($the_request); | |
* | |
* Since objects are passed by refence by default, we can then just use the $the_request | |
* object the controller has mofified, no need to return the request from the controller method. | |
* | |
*/ | |
public function action_article(Http_Request $request) | |
{ | |
try | |
{ | |
$article = Article::find_by_slug($request->get_param('article')); | |
} | |
catch (Fuel_Exception $e) | |
{ | |
return new $request->response = new Http_Response(new View('articles/missing'), 404); | |
} | |
// Should the default status code be 200? | |
$request->response = new Http_Response(); | |
if ($request->is_ajax()) | |
{ | |
$request->response->set_content(json_encode($article)); | |
$request->response->headers->set('Content-Type', 'application/json'); | |
} | |
else | |
{ | |
// $request->response->headers->status_code(500); | |
$request->response->set_content(new View('articles/view', array('article' => $article))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment