上面那,是百度到的,手册上也是这么写的,我的情况是如下,照着写压根取不到值好像/。
划红线那,name或者value,我怎么取到呢?
求教各位高人,谢谢
新截图,下面第一张是存的,第二张是准备取的,我该怎么判断?那个add,是我用户名就是那个,问题是换了名字咋搞啊?我想不明白咋解决,特来求助
][6]
上面那,是百度到的,手册上也是这么写的,我的情况是如下,照着写压根取不到值好像/。
划红线那,name或者value,我怎么取到呢?
求教各位高人,谢谢
新截图,下面第一张是存的,第二张是准备取的,我该怎么判断?那个add,是我用户名就是那个,问题是换了名字咋搞啊?我想不明白咋解决,特来求助
][6]
谢邀,很久没在这边回答了。
$cookie = \Yii::$app->getRequest()->getCookies();
$cookie->get("asd")->name;
$cookie->get("asd")->value;
$cookie->getValue("asd",'这是一个默认值');
这里的$cookie是一个CookieCollection对象,支持获取collection中的cookie对象,第四行中的getValue的实现其实源码里面很简单
yii2/web/CookieCollection.php[91]
/**
* Returns the value of the named cookie.
* @param string $name the cookie name
* @param mixed $defaultValue the value that should be returned when the named cookie does not exist.
* @return mixed the value of the named cookie.
* @see get()
*/
public function getValue($name, $defaultValue = null)
{
return isset($this->_cookies[$name]) ? $this->_cookies[$name]->value : $defaultValue;
}