From 21a51b7cf95fc02b327d65afa0fbba1387800c0e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 10 May 2012 08:44:43 -0500 Subject: [PATCH] Add controller and controller_action to route. --- laravel/routing/controller.php | 18 ++++++++++++------ laravel/routing/route.php | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/laravel/routing/controller.php b/laravel/routing/controller.php index 4e6b4b90..5195a2db 100644 --- a/laravel/routing/controller.php +++ b/laravel/routing/controller.php @@ -154,13 +154,19 @@ abstract class Controller { // improve speed since the bundle is not loaded on every request. Bundle::start($bundle); - list($controller_name, $method) = explode('@', $destination); + list($name, $method) = explode('@', $destination); - $controller = static::resolve($bundle, $controller_name); - - $controller->bundle = $bundle; - $controller->name = $controller_name; - $controller->action = $method; + $controller = static::resolve($bundle, $name); + + // For convenience we will set the current controller and action on the + // Request's route instance so they can be easily accessed from the + // application. This is sometimes useful for dynamic situations. + if ( ! is_null($route = Request::route())) + { + $route->controller = $name; + + $route->controller_action = $method; + } // If the controller could not be resolved, we're out of options and // will return the 404 error response. If we found the controller, diff --git a/laravel/routing/route.php b/laravel/routing/route.php index a297d0d3..73b79521 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -30,6 +30,20 @@ class Route { */ public $bundle; + /** + * The name of the controller used by the route. + * + * @var string + */ + public $controller; + + /** + * The name of the controller action used by the route. + * + * @var string + */ + public $controller_action; + /** * The action that is assigned to the route. *