Skip to content

Commit

Permalink
Working on auto-routing of namespaced controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jul 6, 2016
1 parent fc045b9 commit 60effd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion application/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class Home extends \CodeIgniter\Controller
{

public function index()
{
echo view('welcome_message');
Expand Down
9 changes: 2 additions & 7 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,8 @@ protected function startController()
}
else
{
// Try to load manually.
include APPPATH.'Controllers/'.$this->router->directory().$this->controller.'.php';

// Try to autoload the class, both with and
// without the namespace
if ( (! class_exists($this->controller, true) )
|| $this->method[0] === '_')
// Try to autoload the class
if ( ! class_exists($this->controller, true) || $this->method[0] === '_')
{
throw new PageNotFoundException('Controller or its method is not found.');
}
Expand Down
10 changes: 10 additions & 0 deletions system/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,16 @@ public function autoRoute(string $uri)
{
$this->params = $segments;
}

// Load the file so that it's available for CodeIgniter.
include APPPATH.'Controllers/'.$this->directory.$this->controller.'.php';

// Ensure the controller stores the fully-qualified class name
// We have to check for a length over 1, since by default it will be '\'
if (strpos($this->controller, '\\') === false && strlen($this->collection->getDefaultNamespace()) > 1)
{
$this->controller = str_replace('/', '\\', $this->collection->getDefaultNamespace().$this->directory.$this->controller);
}
}

//--------------------------------------------------------------------
Expand Down

0 comments on commit 60effd6

Please sign in to comment.