Skip to content

Commit

Permalink
There was an issue with checking the implementation of the BaseContro…
Browse files Browse the repository at this point in the history
…ller in the controller object. Also, setDefaultController now takes the controller name as it appears in the URL, not the actual controller class name.
  • Loading branch information
Ian Aldrighetti committed Jun 7, 2014
1 parent 332703c commit 1b3b050
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions LmMvc/Application.php
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions example/example-index.php
Expand Up @@ -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();

0 comments on commit 1b3b050

Please sign in to comment.