From f9bc3cc2dfd899c394cc4f1753fcdb9f2dbddb22 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 16 Jan 2012 14:21:06 -0600 Subject: [PATCH] added before and after methods to the base controller. --- laravel/routing/controller.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index c8173996..c32f4edd 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -136,7 +136,7 @@ protected static function format($bundle, $controller) // If the controller's bundle is not the application bundle, we will // prepend the bundle to the identifier so the bundle is prefixed to // the class name when it is formatted. Bundle controllers are - // always prefixed with the bundle's name by convention. + // always prefixed with the bundle name. if ($bundle !== DEFAULT_BUNDLE) $controller = $bundle.'.'.$controller; return Str::classify($controller).'_Controller'; @@ -159,11 +159,18 @@ public function execute($method, $parameters = array()) if (is_null($response)) { + $this->before(); + $response = $this->response($method, $parameters); } $response = Response::prepare($response); + // The "after" function on the controller is simply a convenient hook + // so the developer can work on the response before it's returned to + // the browser. This is useful for setting partials on the layout. + $this->after($response); + Filter::run($this->filters('after', $method), array($response)); return $response; @@ -265,7 +272,22 @@ public function layout() } /** - * Magic Method to handle calls to undefined functions on the controller. + * This function is called before the action is executed. + * + * @return void + */ + public function before() {} + + /** + * This function is called after the action is executed. + * + * @param Response $response + * @return void + */ + public function after($response) {} + + /** + * Magic Method to handle calls to undefined controller functions. */ public function __call($method, $parameters) {