Skip to content

Central callback/hook before route response is called #405

@felixWackernagel

Description

@felixWackernagel

Each of my routes start with the locale.

$klein->respond( '/', function ($request, $response, $service, $app) {
    $response->redirect( '/en/' );
});
$klein->with('/[*:locale]', function () use ($klein) {
    $klein->respond( 'GET', '/', [HomeController::class, 'get'] );
    $klein->respond( 'GET', '/foo', [FooController::class, 'get']);
});

For rendering i used twig and all information for twig is stored inside a service array called context.

$klein->respond( function ( $request, $response, $service, $app ) {
    $app->context = [
        'pageTitle' => 'Demo Site',
	'locale' => $request->locale
    ];
});

But at time of context initialization is locale null. When my callable of the respond-function is called only then is $request-locale available. I tried different approaches but everytime is locale not available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions