Default params for all cookies

By default, Yii2 enforces


for all cookies set from any place in the code. I want to find a way to automatically set


for all cookies in the same manner.

Currently, I need to set the parameter explicitly for each cookie that I set:

$cookies = Yii::$app->response->cookies;

$cookies->add(new yii\web\Cookie([

    'name' => '_country',

    'value' => $country,

    'expire' => time() + 3600*24*7*365,

    'secure' => true,


You can extend yii\web\Cookie to your own class, set secure parameter there to true and use this new class instead of yii\web\Cookie everywhere.