Through the returned cookie collection, you may access a cookie using the following syntax:
php
$cookie = $request->cookies['name']
if ($cookie !== null) {
$value = $cookie->value;
}
alternatively
$value = $request->cookies->getValue('name');
public getCookies ( ) : |
||
return | the cookie collection. |
/** * 从请求中获取值,包含POST和GET请求域以及通过php://input获取的数据 * @param $key * @param string $value * @return string */ protected function get($key, $value = '') { $params = ArrayHelper::merge($_GET, $_POST); if (isset($params[$key])) { return $params[$key]; } foreach ($this->request->getBodyParams() as $k => $val) { if (!isset($params[$k])) { $params[$k] = $val; } } if (isset($params[$key])) { return $params[$key]; } if ($this->request->getCookies()->has($key)) { return $this->request->getCookies()->getValue($key); } return $value; }