From 1b3b050484f5ba9552ddde417d3187f22591cea7 Mon Sep 17 00:00:00 2001 From: Ian Aldrighetti Date: Sat, 7 Jun 2014 16:03:14 -0700 Subject: [PATCH] There was an issue with checking the implementation of the BaseController in the controller object. Also, setDefaultController now takes the controller name as it appears in the URL, not the actual controller class name. --- LmMvc/Application.php | 6 ++++-- README.md | 6 +++--- example/example-index.php | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/LmMvc/Application.php b/LmMvc/Application.php index 8ae21a9..8e3f74d 100644 --- a/LmMvc/Application.php +++ b/LmMvc/Application.php @@ -237,7 +237,9 @@ public function getDefaultController() } /** - * The default controller to use when the request URI doesn't specify one. + * The default controller to use when the request URI doesn't specify one. This is not the controller name (the + * actual class name, that is), but the URL that would be used to access the controller (with default controller + * casing, DefaultPage would be default_page). * * @param string $defaultController */ @@ -461,7 +463,7 @@ public function getControllerInstance($controllerName) $controller = new $controllerName(); // It must extend BaseController. - if (!is_subclass_of($controller, '\\LmMvc\\BaseController')) + if (!in_array('LmMvc\\BaseController', class_implements($controller))) { throw new ControllerException( sprintf('The controller "%s" does not inherit BaseController.', htmlspecialchars($controllerName)) diff --git a/README.md b/README.md index fc74966..cfb5a91 100644 --- a/README.md +++ b/README.md @@ -95,12 +95,12 @@ This will make LMMVC try to autoload a controller by the name of my_controller ( ##### setDefaultController -If no cotroller name can be determined from the request URI (i.e. ```/index``` or ```/somepage```), LMMVC must be told what controller to use by default, like so: +If no controller name can be determined from the request URI (i.e. ```/index``` or ```/somepage```), LMMVC must be told what controller to use by default, like so: ```php -$application->setDefaultController('DefaultPage'); +$application->setDefaultController('default_page'); ``` -You cannot include the entire class path (the namespace, that is) when setting this, as the default controller must also reside with the rest of the controllers as well. +Note, as above, that this is not the actual name of the controller in it's implementation, but the controller name that would appear in the URL based on the controller casing being used. For example, with default controller casing ```DefaultPage``` would be specified as ```default_page```. ##### run diff --git a/example/example-index.php b/example/example-index.php index fa6a192..37b1a15 100644 --- a/example/example-index.php +++ b/example/example-index.php @@ -32,8 +32,8 @@ $application->setNamespace('\\Application\\Controller'); // If no controller name can be determined from the URL, we will use the default: -// (do not include the namespace of the controller -- it will not work! it must belong to the namespace set above) -$application->setDefaultController('DefaultPage'); +// (do not use the name of the controller class, but the name that would be used in the URL) +$application->setDefaultController('default_page'); // There isn't anything else to do, so have LMMVC route the request. $application->run(); \ No newline at end of file