Yii2.0 Cookies操作

1.添加修改cookies

$cookie=array("name"=>"user","value"=>"demo1","expire"=>24*3600,‘httpOnly' => true,);
Yii::$app->response->cookies->add(new Cookie($cookie));

2.删除cookies

Yii::$app->response->cookies->remove("user");

3.获取cookies

$a=Yii::$app->response->cookies->get('user');//返回一个\yii\web\Cookie对象
$a=Yii::$app->request->cookies->getValue('user');//直接返回Cookie的值
print_r($a);

 




posted @ 2017-06-26 17:18  tengjian  阅读(58)  评论(0编辑  收藏  举报