php - cakePHP 4 how to change session.cookie_lifetime

one text

Solution:

You most likely shouldn't do it that way, your controller code shouldn't have to know about such details if it can be avoided.

The authentication plugin ships with a cookie based authenticator that you can use in addition to the session authenticator, that way you can extend authentication beyond the default session lifetime, I'd suggest that you look into that instead.

$service->loadAuthenticator('Authentication.Cookie', [
    'fields' => $fields,
    'loginUrl' => $loginUrl,
    'cookie' => [
        // cookie expires in 2 days from now
        'expires' => \Cake\Chronos\Chronos::now()->addDays(2)
    ],
]);

By default the authenticator looks up a field named remember_me, so either rename that in your template, like:

echo $this->Form->control('remember_me', ['type' => 'checkbox']);

or configure the authenticator's rememberMeField option with the custom field name that you're using in your form.

See also

Source