Skip to content

setDefaultController not working as expected #1758

Description

@tcrawf

$routes->setDefaultController() method not working as expected
Default controller not being found with autorouting (without route definition)

Situation:
Routes.php file contains
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Pages/showme');

Routes.php does not contain an explicit route definition. The comment in the Routes.php file indicates that this is only required for performance enhancement.

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
//$routes->get('/', 'Pages::showme'); Commented out

A Pages Controller with 'showme' method exists. This is in the Controllers directory and has a namespace of App\Controllers.

Expected behaviour:
Web browser with base url loads the 'showme' method on the Pages controller

Actual behaviour:
404 Controller or its method is not found: App\Controllers\\Pages::showme
If the route is explicitly defined then the route is reached.

It appears that the validateRequest method in Router.php is setting the $this->directory value to '//'. This is leading to auto-routing failing.

CodeIgniter 4 version
v4.0.0-alpha5 develop branch

Affected module(s)
Class Codeigniter\Router
File Router.php

Context

  • OS: [Ubuntu Bionic]
  • Web server [Apache 2.4.2.9]
  • PHP version [PHP 7.2.10-0]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions