Skip to content

Router Regex not working with controllers #2330

Description

@jbotka

Describe the bug
The problem seems to be in the router. My code is like this doesn't work. Error 404.

$routes->group('admin', ['namespace' => '\Admin\Controllers\Auth'], function ($routes){
    $routes->add('(.*)/(.*)', '$1/$2');
});

According to the guide, it should be possible to pass the controller and method name from URL during this. I tried and it works to pass it as method argument and display it in the controller.

It works like this to redirect everything from /admin/* to some defined controller in another namesapce defined like below.

$routes->group('admin', ['namespace' => '\Admin\Controllers\Auth'], function ($routes){
    $routes->add('(.*)', 'myController');
});

This doesn't worka as well. Error 404

$routes->group('admin', ['namespace' => '\Admin\Controllers\Auth'], function ($routes){
    $routes->add('(.*)/(.*)', '$1::$2');
});

Since it doesn't make log when accessing not existing controller. I am assuming it tries to pass segments as arguments to not defined controller all the time and can not pass it as controller name.

CodeIgniter 4 version
4.0.0 rc-2 - develop branch

Affected module(s)

  • Router

Expected behaviour, and steps to reproduce if appropriate
With this code, I expect to pass the first segment after "admin" as controller name and second segment as the method with the defined namespace. This should work according to the user guide.

$routes->group('admin', ['namespace' => '\Admin\Controllers\Auth'], function ($routes){
    $routes->add('(.*)/(.*)', '$1/$2');
});

Context

  • OS: Windows 8.1 x64
  • Apache 2.4.41
  • PHP 7.3.9

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