Skip to content

Missing Feature, routes are empty when trying route_to in filters #9328

Open
@crustamet

Description

@crustamet

I do not know if this is a wanted behaviour or not

But having this Filter Config for example

	public array $globals = [
		'before' => [
			'honeypot' => ['except' => [route_to('some_alias')]],
			// 'csrf',
			// 'invalidchars',
		],
		'after' => [
			// 'honeypot',
			// 'secureheaders',
		],
	];

first it does not allow you to have it as a constant with dynamic strings

so i change the filter config with this addition instead of putting in the globals

	public function __construct()
	{
		$routes = Services::routes();
		
		echo route_to('some_alias'); 

		$this->globals['before']['honeypot']['except'] = [route_to('route_alias')];
	}

It does not work because routes are not loaded yet from the Codeigniter->Run() method because of this piece of code here
https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/CodeIgniter.php#L346

The handling of the request happens after the filters were loaded....

The filters are loaded first then the routes configuration file ... why is that ?
I thought that routes were important without them nothing works, i know there is an AutoRouteImprove feature or what not. even though routes should be already loaded here no ?

I just want to access my routes that i have defined in the filters configuration file...

Is there a way to do this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementPRs that improve existing functionalities

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions