Skip to content

[Routing] Allow using invokable controller's FQCN (i.e. ::class) to generate URLs (instead of route name) #49981

@ThomasLandauer

Description

@ThomasLandauer

Description

With the advent of invokable controllers, it would be possible to move away from using names (i.e. strings) as route idenfifiers, and use the controller's FQCN instead:

#[Route(path: '/some')]
final class SomeController
{
    public function __invoke(): Response
    {
        // ...
    }
}

Then in any service:

$this->router->generate(SomeController::class);

Twig:

{{ path('App\\Controller\\SomeController') }}

Advantage: No more strings! :-)

I got the idea from https://tomasvotruba.com/blog/to-route-or-to-action-thats-the-question which says that this is possible in Laravel:

It allows using the controller directly instead of a middleman string:
+<form action="{{ action(\App\Controllers\ProcessPhpFormController::class) }}" method="post">

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureHelp wantedIssues and PRs which are looking for volunteers to complete them.Routing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions