CCookieCollection
鍖 | system.web |
---|---|
缁ф壙 | class CCookieCollection » CMap » CComponent |
瀹炵幇 | Countable, ArrayAccess, Traversable, IteratorAggregate |
婧愯嚜 | 1.0 |
鐗堟湰 | $Id: CHttpRequest.php 3560 2012-02-10 14:13:00Z mdomba $ |
婧愮爜 | framework/web/CHttpRequest.php |
CCookieCollection implements a collection class to store cookies.
You normally access it via CHttpRequest::getCookies().
Since CCookieCollection extends from CMap, it can be used like an associative array as follows:
You normally access it via CHttpRequest::getCookies().
Since CCookieCollection extends from CMap, it can be used like an associative array as follows:
$cookies[$name]=new CHttpCookie($name,$value); // sends a cookie $value=$cookies[$name]->value; // reads a cookie value unset($cookies[$name]); // removes a cookie
鍏叡灞炴
灞炴 | 绫诲瀷 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|---|
count | integer | 杩斿洖map涓殑椤圭洰鏁般 | CMap |
iterator | CMapIterator | 杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ | CMap |
keys | array | 杩斿洖閿悕鍒楄〃 | CMap |
readOnly | boolean | 杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 | CMap |
request | CHttpRequest | the request instance | CCookieCollection |
鍏叡鏂规硶
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
__call() | 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 | CComponent |
__construct() | Constructor. | CCookieCollection |
__get() | 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 | CComponent |
__isset() | 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 | CComponent |
__set() | 璁剧疆涓涓粍浠剁殑灞炴у笺 | CComponent |
__unset() | 璁剧疆涓涓粍浠剁殑灞炴т负null銆 | CComponent |
add() | Adds a cookie with the specified name. | CCookieCollection |
asa() | 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° | CComponent |
attachBehavior() | 闄勫姞涓涓涓哄埌缁勪欢銆 | CComponent |
attachBehaviors() | 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 | CComponent |
attachEventHandler() | 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 | CComponent |
canGetProperty() | 纭畾灞炴ф槸鍚﹀彲璇汇 | CComponent |
canSetProperty() | 纭畾灞炴ф槸鍚﹀彲鍐欍 | CComponent |
clear() | 鍒犻櫎map涓墍鏈夐」鐩 | CMap |
contains() | CMap | |
copyFrom() | 灏嗚凯浠e櫒涓殑鏁版嵁澶嶅埗鍒癿ap銆 | CMap |
count() | 杩斿洖map涓殑椤圭洰鏁般 | CMap |
detachBehavior() | 浠庣粍浠朵腑鍒嗙涓涓涓恒 | CComponent |
detachBehaviors() | 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 | CComponent |
detachEventHandler() | 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 | CComponent |
disableBehavior() | 绂佺敤涓涓檮鍔犺涓恒 | CComponent |
disableBehaviors() | 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
enableBehavior() | 鍚敤涓涓檮鍔犺涓恒 | CComponent |
enableBehaviors() | 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 | CComponent |
evaluateExpression() | 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 | CComponent |
getCount() | 杩斿洖map涓殑椤圭洰鏁般 | CMap |
getEventHandlers() | 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 | CComponent |
getIterator() | 杩斿洖閬嶅巻杩欎釜鍒楄〃鐨勯」鐩殑杩唬鍣ㄣ | CMap |
getKeys() | 杩斿洖杩斿洖閿悕鍒楄〃 | CMap |
getReadOnly() | 杩斿洖杩斿洖鍊艰鏄庤繖涓垪琛ㄦ槸鍚︿负鍙銆傞粯璁や负false銆 | CMap |
getRequest() | 杩斿洖the request instance | CCookieCollection |
hasEvent() | 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 | CComponent |
hasEventHandler() | 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 | CComponent |
hasProperty() | 纭畾灞炴ф槸鍚﹁瀹氫箟銆 | CComponent |
itemAt() | 杩斿洖鎸囧畾浣嶇疆鐨勯」鐩 | CMap |
mergeArray() | 閫掑綊鍚堝苟涓や釜鎴栧涓暟缁勩 | CMap |
mergeWith() | 灏嗚凯浠e櫒鐨勬暟鎹暣鍚堝埌map銆 | CMap |
offsetExists() | 杩斿洖鍊艰鏄庢寚瀹氫綅缃槸鍚﹀瓨鍦ㄥ厓绱犮 | CMap |
offsetGet() | 杩斿洖鍊兼寚瀹氫綅缃殑鍏冪礌銆 | CMap |
offsetSet() | 璁剧疆鎸囧畾浣嶇疆鐨勫厓绱犮 | CMap |
offsetUnset() | 鍒犻櫎鎸囧畾浣嶇疆鐨勫厓绱犮 | CMap |
raiseEvent() | 鍙戣捣涓涓簨浠躲 | CComponent |
remove() | Removes a cookie with the specified name. | CCookieCollection |
toArray() | CMap |
鍙椾繚鎶ゆ柟娉
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
addCookie() | Sends a cookie. | CCookieCollection |
getCookies() | 杩斿洖list of validated cookies | CCookieCollection |
removeCookie() | Deletes a cookie. | CCookieCollection |
setReadOnly() | 璁剧疆璁剧疆杩欎釜鍒楄〃鏄惁涓哄彧璇 | CMap |
灞炴ц缁
cookies
灞炴
鍙
protected array getCookies()
list of validated cookies
request
灞炴
鍙
public CHttpRequest getRequest()
the request instance
鏂规硶璇︾粏
__construct()
鏂规硶
public void __construct(CHttpRequest $request)
| ||
$request | CHttpRequest | owner of this collection. |
婧愮爜锛 framework/web/CHttpRequest.php#962 (鏄剧ず)
public function __construct(CHttpRequest $request)
{
$this->_request=$request;
$this->copyfrom($this->getCookies());
$this->_initialized=true;
}
Constructor.
add()
鏂规硶
public void add(mixed $name, CHttpCookie $cookie)
| ||
$name | mixed | Cookie name. |
$cookie | CHttpCookie | Cookie object. |
婧愮爜锛 framework/web/CHttpRequest.php#1008 (鏄剧ず)
public function add($name,$cookie)
{
if($cookie instanceof CHttpCookie)
{
$this->remove($name);
parent::add($name,$cookie);
if($this->_initialized)
$this->addCookie($cookie);
}
else
throw new CException(Yii::t('yii','CHttpCookieCollection can only hold CHttpCookie objects.'));
}
Adds a cookie with the specified name. This overrides the parent implementation by performing additional operations for each newly added CHttpCookie object.
addCookie()
鏂规硶
protected void addCookie(CHttpCookie $cookie)
| ||
$cookie | CHttpCookie | cookie to be sent |
婧愮爜锛 framework/web/CHttpRequest.php#1042 (鏄剧ず)
protected function addCookie($cookie)
{
$value=$cookie->value;
if($this->_request->enableCookieValidation)
$value=Yii::app()->getSecurityManager()->hashData(serialize($value));
if(version_compare(PHP_VERSION,'5.2.0','>='))
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else
setcookie($cookie->name,$value,$cookie->expire,$cookie->path,$cookie->domain,$cookie->secure);
}
Sends a cookie.
getCookies()
鏂规硶
protected array getCookies()
| ||
{return} | array | list of validated cookies |
婧愮爜锛 framework/web/CHttpRequest.php#980 (鏄剧ず)
protected function getCookies()
{
$cookies=array();
if($this->_request->enableCookieValidation)
{
$sm=Yii::app()->getSecurityManager();
foreach($_COOKIE as $name=>$value)
{
if(is_string($value) && ($value=$sm->validateData($value))!==false)
$cookies[$name]=new CHttpCookie($name,@unserialize($value));
}
}
else
{
foreach($_COOKIE as $name=>$value)
$cookies[$name]=new CHttpCookie($name,$value);
}
return $cookies;
}
getRequest()
鏂规硶
public CHttpRequest getRequest()
| ||
{return} | CHttpRequest | the request instance |
婧愮爜锛 framework/web/CHttpRequest.php#972 (鏄剧ず)
public function getRequest()
{
return $this->_request;
}
remove()
鏂规硶
public CHttpCookie remove(mixed $name)
| ||
$name | mixed | Cookie name. |
{return} | CHttpCookie | The removed cookie object. |
婧愮爜锛 framework/web/CHttpRequest.php#1028 (鏄剧ず)
public function remove($name)
{
if(($cookie=parent::remove($name))!==null)
{
if($this->_initialized)
$this->removeCookie($cookie);
}
return $cookie;
}
Removes a cookie with the specified name. This overrides the parent implementation by performing additional cleanup work when removing a CHttpCookie object.
removeCookie()
鏂规硶
protected void removeCookie(CHttpCookie $cookie)
| ||
$cookie | CHttpCookie | cookie to be deleted |
婧愮爜锛 framework/web/CHttpRequest.php#1057 (鏄剧ず)
protected function removeCookie($cookie)
{
if(version_compare(PHP_VERSION,'5.2.0','>='))
setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure,$cookie->httpOnly);
else
setcookie($cookie->name,null,0,$cookie->path,$cookie->domain,$cookie->secure);
}
Deletes a cookie.