Skip to content

Commit

Permalink
fix: $routes->setDefaultMethod() does not work
Browse files Browse the repository at this point in the history
The default method may be not `index`, and it is set in the constructor.
  • Loading branch information
kenjis committed Feb 12, 2022
1 parent d76e2a2 commit f6cce24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 1 addition & 4 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,7 @@ protected function setDefaultController()
throw RouterException::forMissingDefaultRoute();
}

// Is the method being specified?
if (sscanf($this->controller, '%[^/]/%s', $class, $this->method) !== 2) {
$this->method = 'index';
}
sscanf($this->controller, '%[^/]/%s', $class, $this->method);

if (! is_file(APPPATH . 'Controllers/' . $this->directory . ucfirst($class) . '.php')) {
return;
Expand Down
12 changes: 12 additions & 0 deletions tests/system/Router/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ public function testClosures()
$this->assertSame($expects, '123-alpha');
}

public function testAutoRouteFindsDefaultControllerAndMethod()
{
$this->collection->setDefaultController('Test');
$this->collection->setDefaultMethod('test');
$router = new Router($this->collection, $this->request);

$router->autoRoute('/');

$this->assertSame('Test', $router->controllerName());
$this->assertSame('test', $router->methodName());
}

public function testAutoRouteFindsControllerWithFileAndMethod()
{
$router = new Router($this->collection, $this->request);
Expand Down

0 comments on commit f6cce24

Please sign in to comment.