2015-05-28 16:39:13 5766次浏览 2条回答 0 悬赏 5 金钱

官网的例子如下:

// get the cookie collection (yii\web\CookieCollection) from the "response" component
$cookies = Yii::$app->response->cookies;

// add a new cookie to the response to be sent
$cookies->add(new \yii\web\Cookie([
    'name' => 'language',
    'value' => 'zh-CN',
]));

但问题是我有一个数组,如何可以快速批量添加?是否支持:

// get the cookie collection (yii\web\CookieCollection) from the "response" component
$cookies = Yii::$app->response->cookies;

// add a new cookie to the response to be sent
$cookies->add(new \yii\web\Cookie([
    'k1' => 'v1',
    'k2' => 'v2',
    'k3' => 'v3',
]));

  • 回答于 2015-05-28 17:43 举报

    据我所知,只能循环你的key value数组,然后一个个的new Cookie()$cookies->add()

  • 回答于 2016-08-02 10:42 举报

    可以把数组序列化之后作为value存进去

您需要登录后才可以回答。登录 | 立即注册
phptest
见习主管

phptest

注册时间:2014-06-08
最后登录:2018-12-03
在线时长:9小时54分
  • 粉丝5
  • 金钱118
  • 威望0
  • 积分208

热门问题