From 8da1c16c8bbb48c77b4637fe535bdeaf6782a306 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 5 Mar 2012 13:31:30 -0600 Subject: [PATCH] Tweak controller layout resolution. Signed-off-by: Taylor Otwell --- laravel/routing/controller.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index d6d3afe5..e095f74b 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -46,6 +46,22 @@ abstract class Controller { */ const factory = 'laravel.controller.factory'; + /** + * Create a new Controller instance. + * + * @return void + */ + public function __construct() + { + // If the controller has specified a layout to be used when rendering + // views, we will instantiate the layout instance and set it to the + // layout property, replacing the string layout name. + if ( ! is_null($this->layout)) + { + $this->layout = $this->layout(); + } + } + /** * Call an action method on a controller. * @@ -141,22 +157,12 @@ public static function resolve($bundle, $controller) // by convention out of the bundle's controller directory. if (Event::listeners(static::factory)) { - $controller = Event::first(static::factory, $controller); + return Event::first(static::factory, $controller); } else { - $controller = new $controller; + return new $controller; } - - // If the controller has specified a layout to be used when rendering - // views, we will instantiate the layout instance and set it to the - // layout property, replacing the string layout name. - if ( ! is_null($controller->layout)) - { - $controller->layout = $controller->layout(); - } - - return $controller; } /**