CDbHttpSession
包 | system.web |
---|---|
继承 | class CDbHttpSession » CHttpSession » CApplicationComponent » CComponent |
实现 | Countable, ArrayAccess, Traversable, IteratorAggregate, IApplicationComponent |
可用自 | 1.0 |
版本 | $Id$ |
CDbHttpSession stores session data in a DB table named 'YiiSession'. The table name can be changed by setting sessionTableName. If the table does not exist, it will be automatically created if autoCreateSessionTable is set true.
CDbHttpSession relies on PDO to access database.
By default, it will use an SQLite3 database named 'session-YiiVersion.db' under the application runtime directory. You can also specify connectionID so that it makes use of a DB application component to access database.
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
autoCreateSessionTable | boolean | whether the session DB table should be automatically created if not exists. | CDbHttpSession |
autoStart | boolean | whether the session should be automatically started when the session application component is initialized, defaults to true. | CHttpSession |
behaviors | array | the behaviors that should be attached to this component. | CApplicationComponent |
connectionID | string | the ID of a CDbConnection application component. | CDbHttpSession |
cookieMode | string | how to use cookie to store session ID. | CHttpSession |
cookieParams | array | the session cookie parameters. | CHttpSession |
count | integer | the number of session variables | CHttpSession |
gCProbability | integer | the probability (percentage) that the gc (garbage collection) process is started on every session initialization, defaults to 1 meaning 1% chance. | CHttpSession |
isInitialized | boolean | whether this application component has been initialized (i. | CApplicationComponent |
isStarted | boolean | whether the session has started | CHttpSession |
iterator | CHttpSessionIterator | Returns an iterator for traversing the session variables. | CHttpSession |
keys | array | the list of session variable names | CHttpSession |
savePath | string | the current session save path, defaults to '/tmp'. | CHttpSession |
sessionID | string | the current session ID | CHttpSession |
sessionName | string | the current session name | CHttpSession |
sessionTableName | string | the name of the DB table to store session content. | CDbHttpSession |
timeout | integer | the number of seconds after which data will be seen as 'garbage' and cleaned up, defaults to 1440 seconds. | CHttpSession |
useCustomStorage | boolean | Returns a value indicating whether to use custom session storage. | CDbHttpSession |
useTransparentSessionID | boolean | whether transparent sid support is enabled or not, defaults to false. | CHttpSession |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
add() | Adds a session variable. | CHttpSession |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
clear() | Removes all session variables | CHttpSession |
close() | Ends the current session and store session data. | CHttpSession |
closeSession() | Session close handler. | CHttpSession |
contains() | CHttpSession | |
count() | Returns the number of items in the session. | CHttpSession |
destroy() | Frees all session variables and destroys all data registered to a session. | CHttpSession |
destroySession() | Session destroy handler. | CDbHttpSession |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
gcSession() | Session GC (garbage collection) handler. | CDbHttpSession |
getCookieMode() | CHttpSession | |
getCookieParams() | CHttpSession | |
getCount() | CHttpSession | |
getEventHandlers() | Returns the list of attached event handlers for an event. | CComponent |
getGCProbability() | CHttpSession | |
getIsInitialized() | CApplicationComponent | |
getIsStarted() | CHttpSession | |
getIterator() | Returns an iterator for traversing the session variables. | CHttpSession |
getKeys() | CHttpSession | |
getSavePath() | CHttpSession | |
getSessionID() | CHttpSession | |
getSessionName() | CHttpSession | |
getTimeout() | CHttpSession | |
getUseCustomStorage() | Returns a value indicating whether to use custom session storage. | CDbHttpSession |
getUseTransparentSessionID() | CHttpSession | |
hasEvent() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
init() | Initializes the application component. | CHttpSession |
itemAt() | Returns the session variable value with the session variable name. | CHttpSession |
offsetExists() | This method is required by the interface ArrayAccess. | CHttpSession |
offsetGet() | This method is required by the interface ArrayAccess. | CHttpSession |
offsetSet() | This method is required by the interface ArrayAccess. | CHttpSession |
offsetUnset() | This method is required by the interface ArrayAccess. | CHttpSession |
open() | Starts the session if it has not started yet. | CHttpSession |
openSession() | Session open handler. | CDbHttpSession |
raiseEvent() | Raises an event. | CComponent |
readSession() | Session read handler. | CDbHttpSession |
remove() | Removes a session variable. | CHttpSession |
setCookieMode() | CHttpSession | |
setCookieParams() | Sets the session cookie parameters. | CHttpSession |
setGCProbability() | CHttpSession | |
setSavePath() | CHttpSession | |
setSessionID() | CHttpSession | |
setSessionName() | CHttpSession | |
setTimeout() | CHttpSession | |
setUseTransparentSessionID() | CHttpSession | |
toArray() | CHttpSession | |
writeSession() | Session write handler. | CDbHttpSession |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
createSessionTable() | Creates the session DB table. | CDbHttpSession |
getDbConnection() | CDbHttpSession |
属性详情
whether the session DB table should be automatically created if not exists. Defaults to true.
the ID of a CDbConnection application component. If not set, a SQLite database
will be automatically created and used. The SQLite database file is
is protected/runtime/session-YiiVersion.db
.
the DB connection instance
the name of the DB table to store session content. Note, if autoCreateSessionTable is false and you want to create the DB table manually by yourself, you need to make sure the DB table is of the following structure:
(id CHAR(32) PRIMARY KEY, expire INTEGER, data TEXT)
Returns a value indicating whether to use custom session storage. This method overrides the parent implementation and always returns true.
方法详情
protected void createSessionTable(CDbConnection $db, string $tableName)
| ||
$db | CDbConnection | the database connection |
$tableName | string | the name of the table to be created |
Creates the session DB table.
public boolean destroySession(string $id)
| ||
$id | string | session ID |
{return} | boolean | whether session is destroyed successfully |
Session destroy handler. Do not call this method directly.
public boolean gcSession(integer $maxLifetime)
| ||
$maxLifetime | integer | the number of seconds after which data will be seen as 'garbage' and cleaned up. |
{return} | boolean | whether session is GCed successfully |
Session GC (garbage collection) handler. Do not call this method directly.
protected CDbConnection getDbConnection()
| ||
{return} | CDbConnection | the DB connection instance |
public boolean getUseCustomStorage()
| ||
{return} | boolean | whether to use custom storage. |
Returns a value indicating whether to use custom session storage. This method overrides the parent implementation and always returns true.
public boolean openSession(string $savePath, string $sessionName)
| ||
$savePath | string | session save path |
$sessionName | string | session name |
{return} | boolean | whether session is opened successfully |
Session open handler. Do not call this method directly.
public string readSession(string $id)
| ||
$id | string | session ID |
{return} | string | the session data |
Session read handler. Do not call this method directly.
public boolean writeSession(string $id, string $data)
| ||
$id | string | session ID |
$data | string | session data |
{return} | boolean | whether session write is successful |
Session write handler. Do not call this method directly.