From 5d4131b2d8a156e0793a185987292c35a898e332 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 30 Sep 2013 12:22:29 +0300 Subject: Update the Session library docs Signed-off-by: Michael --- user_guide_src/source/libraries/sessions.rst | 65 +++++++++++++++------------- 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 36c7c1d32..51bcc8022 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -21,11 +21,12 @@ initializing the class will cause it to read, create, and update sessions. To initialize the Session class manually in your controller constructor, -use the $this->load->driver function:: +use the ``$this->load->driver`` function:: $this->load->driver('session'); -Once loaded, the Sessions library object will be available using: +Once loaded, the Sessions library object will be available using:: + $this->session How do Sessions work? @@ -49,23 +50,23 @@ What is Session Data? A *session*, as far as CodeIgniter is concerned, is simply an array containing the following information: -- The user's unique Session ID (this is a statistically random string +* The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes) -- The user's IP Address -- The user's User Agent data (the first 120 characters of the browser +* The user's IP Address +* The user's User Agent data (the first 120 characters of the browser data string) -- The "last activity" time stamp. +* The "last activity" time stamp. The above data is stored in a cookie as a serialized array with this prototype:: [array] ( - 'session_id' => random hash, - 'ip_address' => 'string - user IP address', - 'user_agent' => 'string - user agent data', - 'last_activity' => timestamp + 'session_id' => random hash, + 'ip_address' => 'string - user IP address', + 'user_agent' => 'string - user agent data', + 'last_activity' => timestamp ) .. note:: Sessions are only updated every five minutes by default to @@ -112,21 +113,21 @@ Where $array is an associative array containing your new data. Here's an example:: $newdata = array( - 'username' => 'johndoe', - 'email' => 'johndoe@some-site.com', - 'logged_in' => TRUE - ); + 'username' => 'johndoe', + 'email' => 'johndoe@some-site.com', + 'logged_in' => TRUE + ); $this->session->set_userdata($newdata); -If you want to add userdata one value at a time, set_userdata() also +If you want to add userdata one value at a time, ``set_userdata()`` also supports this syntax. :: $this->session->set_userdata('some_name', 'some_value'); -If you want to verify that a userdata value exists, call has_userdata(). +If you want to verify that a userdata value exists, call ``has_userdata()``. :: @@ -143,10 +144,10 @@ And returns an associative array like the following:: Array ( - [session_id] => 4a5a5dca22728fb0a84364eeb405b601 - [ip_address] => 127.0.0.1 - [user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; - [last_activity] => 1303142623 + [session_id] => 4a5a5dca22728fb0a84364eeb405b601 + [ip_address] => 127.0.0.1 + [user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; + [last_activity] => 1303142623 ) Removing Session Data @@ -185,8 +186,8 @@ To add flashdata:: $this->session->set_flashdata('item', 'value'); -You can also pass an array to set_flashdata(), in the same manner as -set_userdata(). +You can also pass an array to ``set_flashdata()``, in the same manner as +``set_userdata()``. To read a flashdata variable:: @@ -198,7 +199,7 @@ An array of all flashdata can be retrieved as follows:: If you find that you need to preserve a flashdata variable through an -additional request, you can do so using the keep_flashdata() function. +additional request, you can do so using the ``keep_flashdata()`` function. You can either pass a single item or an array of flashdata items to keep. :: @@ -206,6 +207,8 @@ You can either pass a single item or an array of flashdata items to keep. $this->session->keep_flashdata('item'); $this->session->keep_flashdata(array('item1', 'item2', 'item3')); +.. note:: The function will return NULL if the item cannot be found. + Tempdata ======== @@ -219,7 +222,7 @@ To add tempdata:: $this->session->set_tempdata('item', 'value', $expire); -You can also pass an array to set_tempdata():: +You can also pass an array to ``set_tempdata()``:: $tempdata = array('newuser' => TRUE, 'message' => 'Thanks for joining!'); @@ -233,7 +236,7 @@ To read a tempdata variable:: $this->session->tempdata('item'); If you need to remove a tempdata value before it expires, -use unset_tempdata():: +use ``unset_tempdata()``:: $this->session->unset_tempdata('item'); @@ -246,7 +249,7 @@ To clear the current session:: .. note:: This function should be the last one called, and even flash variables will no longer be available. If you only want some items - destroyed and not all, use unset_userdata(). + destroyed and not all, use ``unset_userdata()``. Session Preferences =================== @@ -303,7 +306,7 @@ installed, and `Custom Drivers`_ may also be installed by the user. Typically, only one driver will be used at a time, but CodeIgniter does support loading multiple drivers. If a specific valid driver is called, it will be automatically loaded. Or, an additional driver may be explicitly -loaded by calling load_driver():: +loaded by ``calling load_driver()``:: $this->session->load_driver('native'); @@ -328,7 +331,7 @@ the call to unset the *native* 'foo' value. The drivers maintain independent sets of values, regardless of key names. A specific driver may also be explicitly selected for use by pursuant -methods with the select_driver() call:: +methods with the ``select_driver()`` call:: $this->session->select_driver('native'); @@ -422,7 +425,7 @@ You may also :doc:`create your own <../general/creating_drivers>` custom session drivers. A session driver basically manages an array of name/value pairs with some sort of storage mechanism. -To make a new driver, extend CI_Session_driver. Overload the initialize() +To make a new driver, extend CI_Session_driver. Overload the ``initialize()`` method and read or create session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler to remove deleted data (sess_destroy), a regenerate handler to make a new session ID @@ -456,13 +459,13 @@ Your initial class might look like:: } } -Notice that get_userdata() returns a reference so the parent library is +Notice that ``get_userdata()`` returns a reference so the parent library is accessing the same array the driver object is using. This saves memory and avoids synchronization issues during usage. Put your driver in the libraries/Session/drivers folder anywhere in your package paths. This includes the application directory, the system directory, -or any path you add with $CI->load->add_package_path(). Your driver must be +or any path you add with ``$CI->load->add_package_path()``. Your driver must be named CI_Session_, and your filename must be Session_.php, preferably also capitalized, such as:: -- cgit v1.2.3-24-g4f1b From 1c7438f08bf289c08d5d1c466316850831b9b0ed Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Oct 2013 15:21:21 +0300 Subject: Added class reference to the session docs Signed-off-by: Michael --- user_guide_src/source/libraries/sessions.rst | 193 ++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 4 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 51bcc8022..3dc067a70 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -50,13 +50,13 @@ What is Session Data? A *session*, as far as CodeIgniter is concerned, is simply an array containing the following information: -* The user's unique Session ID (this is a statistically random string +- The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes) -* The user's IP Address -* The user's User Agent data (the first 120 characters of the browser +- The user's IP Address +- The user's User Agent data (the first 120 characters of the browser data string) -* The "last activity" time stamp. +- The "last activity" time stamp. The above data is stored in a cookie as a serialized array with this prototype:: @@ -486,3 +486,188 @@ without making it the initially loaded driver, set 'sess_valid_drivers' in your config.php file to an array including your driver name:: $config['sess_valid_drivers'] = array('sess_driver'); + + + +*************** +Class Reference +*************** + +.. class:: CI_Session + +Userdata +-------- + + .. method:: set_userdata($newdata = array(), $newval) + + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :returns: void + + Sets items into session example usages:: + + $this->session->set_userdata('user', 'example@example.com'); + // adds item user with value example@example.com to the session + + $this->session->set_userdata(array('user'=>'example@example.com')); + // does the same as the above example - adds item user with value example@example.com to the session + + .. method:: userdata($item) + + :param string $item: name of session item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->userdata('user'); + //returns example@example.com considering the set_userdata example. + + .. method:: unset_userdata($item) + + :param mixed $item: name of item or array of items + :returns: void + + Unsets previously setted items from the session. Example:: + + $this->session->unset_userdata('user'); + //unsets 'user' from session data. + + $this->session->unset_userdata(array('user', 'useremail')); + //unsets both 'user' nad 'useremail' from the session data. + + .. method:: has_userdata($item) + + :param string $item: name of item + :returns: bool + + Checks if an item exists in the session. + + .. method:: all_userdata() + + :returns: array + + Retruns array of userdata session items + + + +Flashdata +--------- +.. note:: the flashdata items are available only one server request + + .. method:: set_flashdata($newdata = array(), $newval) + + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :returns: void + + Sets items into session flashdata example usages:: + + $this->session->set_flashdata('message', 'Test message.'); + // adds item 'message' with value 'Test message.' to the session flashdata + + $this->session->set_flashdata(array('message'=>'Test message.')); + // does the same as the above example - adds item 'message' with value 'Test message.' + to the session flashdata + + .. method:: flashdata($item) + + :param string $item: name of session item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->flashdata('message'); + //returns 'Test message.' considering the set_flashdata example. + + .. method:: has_flashdata($item) + + :param string $item: name of item + :returns: bool + + Checks if an item exists in the session flashdata. + + .. method:: all_flashdata() + + :returns: array + + Retruns array of flashdata session items + + .. method:: keep_flashdata($item) + + :param mixed $item: name of item or array of flashdata items + :returns: void + + Keeps items into flashdata for one more request + + +Tempdata +-------- + + .. method:: set_tempdata($newdata = array(), $newval, $expires) + + :param mixed $newdata: Item name or array of items + :param string $newval: Item value or empty string (not required if $newdata is array) + :param int $expires: lifetime in seconds (0 for default) + :returns: void + + Sets items into session tempdata example:: + + $this->session->set_tempdata('message', 'Test message.', '60'); + // adds item 'message' with value 'Test message.' to the session tempdata for 60 seconds + + $this->session->set_tempdata(array('message'=>'Test message.')); + // does the same as the above example - adds item 'message' with value 'Test message.' + to the session tempdata for the default value of + + .. method:: tempdata($item) + + :param string $item: name of tempdata item + :returns: string + + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + + $this->session->tempdata('message'); + //returns 'Test message.' considering the set_tempdata example. + + .. method:: unset_tempdata($item) + + :param mixed $item: name of item or array of items + :returns: void + + Unsets previously setted items from the tempdata. Example:: + + $this->session->unset_tempdata('user'); + //unsets 'user' from tempdata. + + $this->session->unset_tempdata(array('user', 'useremail')); + //unsets both 'user' nad 'useremail' from the tempdata. + +Session +------- + + .. method:: sess_destroy() + + Destroys current session + .. note:: This function should be the last one called, and even flash variables will no longer be available. + If you only want some items destroyed and not all, use ``unset_userdata()``. + + .. method:: sess_regenerate($destroy) + + :param bool $destroy: Destroy session data flag (default: false) + :returns: void + + Regenerate the current session data + + .. method:: load_driver($driver) + + :param string $driver: Driver name + :returns: object Loaded driver object + + Loads a session storage driver + + .. method:: select_driver($driver) + + :param string $driver: Driver name + :returns: void + + Selects default session storage driver. -- cgit v1.2.3-24-g4f1b From e0a631c3353ea26483e3958306fb2b53d7558a21 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 20 Oct 2013 10:40:51 +0300 Subject: refactored the class reference in session.rst to properly reflect the session class Signed-off-by: Michael --- user_guide_src/source/libraries/sessions.rst | 145 +++++++++++---------------- 1 file changed, 61 insertions(+), 84 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 3dc067a70..cab7669ae 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -495,22 +495,32 @@ Class Reference .. class:: CI_Session -Userdata --------- + .. method:: load_driver($driver) - .. method:: set_userdata($newdata = array(), $newval) + :param string $driver: Driver name + :returns: object Loaded driver object - :param mixed $newdata: Item name or array of items - :param mixed $newval: Item value or empty string (not required if $newdata is array) + Loads a session storage driver + + .. method:: select_driver($driver) + + :param string $driver: Driver name :returns: void - Sets items into session example usages:: + Selects default session storage driver. - $this->session->set_userdata('user', 'example@example.com'); - // adds item user with value example@example.com to the session + .. method:: sess_destroy() - $this->session->set_userdata(array('user'=>'example@example.com')); - // does the same as the above example - adds item user with value example@example.com to the session + Destroys current session + .. note:: This function should be the last one called, and even flash variables will no longer be available. + If you only want some items destroyed and not all, use ``unset_userdata()``. + + .. method:: sess_regenerate($destroy) + + :param bool $destroy: Destroy session data flag (default: false) + :returns: void + + Regenerate the current session data .. method:: userdata($item) @@ -522,6 +532,32 @@ Userdata $this->session->userdata('user'); //returns example@example.com considering the set_userdata example. + .. method:: all_userdata() + + :returns: array + + Retruns array of userdata session items + + .. method:: all_flashdata() + + :returns: array + + Retruns array of flashdata session items + + .. method:: set_userdata($newdata = array(), $newval) + + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :returns: void + + Sets items into session example usages:: + + $this->session->set_userdata('user', 'example@example.com'); + // adds item user with value example@example.com to the session + + $this->session->set_userdata(array('user'=>'example@example.com')); + // does the same as the above example - adds item user with value example@example.com to the session + .. method:: unset_userdata($item) :param mixed $item: name of item or array of items @@ -533,7 +569,7 @@ Userdata //unsets 'user' from session data. $this->session->unset_userdata(array('user', 'useremail')); - //unsets both 'user' nad 'useremail' from the session data. + //unsets both 'user' and 'useremail' from the session data. .. method:: has_userdata($item) @@ -542,18 +578,6 @@ Userdata Checks if an item exists in the session. - .. method:: all_userdata() - - :returns: array - - Retruns array of userdata session items - - - -Flashdata ---------- -.. note:: the flashdata items are available only one server request - .. method:: set_flashdata($newdata = array(), $newval) :param mixed $newdata: Item name or array of items @@ -569,6 +593,13 @@ Flashdata // does the same as the above example - adds item 'message' with value 'Test message.' to the session flashdata + .. method:: keep_flashdata($item) + + :param mixed $item: name of item or array of flashdata items + :returns: void + + Keeps items into flashdata for one more request + .. method:: flashdata($item) :param string $item: name of session item @@ -579,30 +610,6 @@ Flashdata $this->session->flashdata('message'); //returns 'Test message.' considering the set_flashdata example. - .. method:: has_flashdata($item) - - :param string $item: name of item - :returns: bool - - Checks if an item exists in the session flashdata. - - .. method:: all_flashdata() - - :returns: array - - Retruns array of flashdata session items - - .. method:: keep_flashdata($item) - - :param mixed $item: name of item or array of flashdata items - :returns: void - - Keeps items into flashdata for one more request - - -Tempdata --------- - .. method:: set_tempdata($newdata = array(), $newval, $expires) :param mixed $newdata: Item name or array of items @@ -619,16 +626,6 @@ Tempdata // does the same as the above example - adds item 'message' with value 'Test message.' to the session tempdata for the default value of - .. method:: tempdata($item) - - :param string $item: name of tempdata item - :returns: string - - Returns a string containing the value of the passed item or NULL if the item is not found. Example:: - - $this->session->tempdata('message'); - //returns 'Test message.' considering the set_tempdata example. - .. method:: unset_tempdata($item) :param mixed $item: name of item or array of items @@ -640,34 +637,14 @@ Tempdata //unsets 'user' from tempdata. $this->session->unset_tempdata(array('user', 'useremail')); - //unsets both 'user' nad 'useremail' from the tempdata. - -Session -------- - - .. method:: sess_destroy() - - Destroys current session - .. note:: This function should be the last one called, and even flash variables will no longer be available. - If you only want some items destroyed and not all, use ``unset_userdata()``. - - .. method:: sess_regenerate($destroy) - - :param bool $destroy: Destroy session data flag (default: false) - :returns: void - - Regenerate the current session data + //unsets both 'user' and 'useremail' from the tempdata. - .. method:: load_driver($driver) - - :param string $driver: Driver name - :returns: object Loaded driver object - - Loads a session storage driver + .. method:: tempdata($item) - .. method:: select_driver($driver) + :param string $item: name of tempdata item + :returns: string - :param string $driver: Driver name - :returns: void + Returns a string containing the value of the passed item or NULL if the item is not found. Example:: - Selects default session storage driver. + $this->session->tempdata('message'); + //returns 'Test message.' considering the set_tempdata example. -- cgit v1.2.3-24-g4f1b From b57b2ade712990b9214ffaf80ae97829b91303db Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 12:02:08 +0200 Subject: [ci skip] Add/remove some newlines from the session docs --- user_guide_src/source/libraries/sessions.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index cab7669ae..b3de2252c 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -433,6 +433,7 @@ deleted data (sess_destroy), a regenerate handler to make a new session ID Your initial class might look like:: class CI_Session_custom extends CI_Session_driver { + protected function initialize() { // Read existing session data or create a new one @@ -457,6 +458,7 @@ Your initial class might look like:: { // Return a reference to your userdata array } + } Notice that ``get_userdata()`` returns a reference so the parent library is @@ -488,7 +490,6 @@ your config.php file to an array including your driver name:: $config['sess_valid_drivers'] = array('sess_driver'); - *************** Class Reference *************** @@ -647,4 +648,4 @@ Class Reference Returns a string containing the value of the passed item or NULL if the item is not found. Example:: $this->session->tempdata('message'); - //returns 'Test message.' considering the set_tempdata example. + //returns 'Test message.' considering the set_tempdata example. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From cc042095bcce9856402cc04997f44310074716e0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 3 Jan 2014 17:08:27 +0200 Subject: [ci skip] Some more generic user guide cleanup --- user_guide_src/source/libraries/sessions.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index b3de2252c..8e117bee6 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -9,6 +9,13 @@ which supports usage of the native PHP Session mechanism. In addition, you may create your own `Custom Drivers`_ to store session data however you wish, while still taking advantage of the features of the Session class. +.. contents:: + :local: + +.. raw:: html + +
+ Initializing a Session ====================== @@ -27,7 +34,7 @@ use the ``$this->load->driver`` function:: Once loaded, the Sessions library object will be available using:: -$this->session + $this->session How do Sessions work? ===================== -- cgit v1.2.3-24-g4f1b From 1ee5a997279e3f2c6fb20fb648d3620d8b1a14f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 6 Jan 2014 13:08:47 +0200 Subject: [ci skip] Update the Session library docs --- user_guide_src/source/libraries/sessions.rst | 60 +++++++++++++++------------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 8e117bee6..4ce355606 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -506,7 +506,7 @@ Class Reference .. method:: load_driver($driver) :param string $driver: Driver name - :returns: object Loaded driver object + :returns: object Loads a session storage driver @@ -520,22 +520,26 @@ Class Reference .. method:: sess_destroy() Destroys current session - .. note:: This function should be the last one called, and even flash variables will no longer be available. - If you only want some items destroyed and not all, use ``unset_userdata()``. - .. method:: sess_regenerate($destroy) + .. note:: This method should be the last one called, and even flash + variables will no longer be available after it is used. + If you only want some items destroyed and not all, use + ``unset_userdata()``. - :param bool $destroy: Destroy session data flag (default: false) + .. method:: sess_regenerate([$destroy = FALSE]) + + :param bool $destroy: Whether to destroy session data :returns: void - Regenerate the current session data + Regenerate the current session data. .. method:: userdata($item) - :param string $item: name of session item + :param string $item: Session item name :returns: string - Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + Returns a string containing the value of the passed item or NULL if the item is not found. + Example:: $this->session->userdata('user'); //returns example@example.com considering the set_userdata example. @@ -544,15 +548,15 @@ Class Reference :returns: array - Retruns array of userdata session items + Retruns an array with all of the session userdata items. .. method:: all_flashdata() :returns: array - Retruns array of flashdata session items + Retruns an array with all of the session flashdata items. - .. method:: set_userdata($newdata = array(), $newval) + .. method:: set_userdata($newdata[, $newval = '']) :param mixed $newdata: Item name or array of items :param mixed $newval: Item value or empty string (not required if $newdata is array) @@ -568,10 +572,10 @@ Class Reference .. method:: unset_userdata($item) - :param mixed $item: name of item or array of items + :param mixed $item: Item name or an array containing multiple items :returns: void - Unsets previously setted items from the session. Example:: + Unsets previously set items from the session. Example:: $this->session->unset_userdata('user'); //unsets 'user' from session data. @@ -581,14 +585,14 @@ Class Reference .. method:: has_userdata($item) - :param string $item: name of item + :param string $item: Item name :returns: bool Checks if an item exists in the session. - .. method:: set_flashdata($newdata = array(), $newval) + .. method:: set_flashdata($newdata[, $newval = '']) - :param mixed $newdata: Item name or array of items + :param mixed $newdata: Item name or an array of items :param mixed $newval: Item value or empty string (not required if $newdata is array) :returns: void @@ -603,26 +607,27 @@ Class Reference .. method:: keep_flashdata($item) - :param mixed $item: name of item or array of flashdata items + :param mixed $item: Item name or an array containing multiple flashdata items :returns: void - Keeps items into flashdata for one more request + Keeps items into flashdata for one more request. .. method:: flashdata($item) - :param string $item: name of session item + :param string $item: Flashdata item name :returns: string - Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + Returns a string containing the value of the passed item or NULL if the item is not found. + Example:: $this->session->flashdata('message'); //returns 'Test message.' considering the set_flashdata example. - .. method:: set_tempdata($newdata = array(), $newval, $expires) + .. method:: set_tempdata($newdata[, $newval = ''[, $expire = 0]]) - :param mixed $newdata: Item name or array of items + :param mixed $newdata: Item name or array containing multiple items :param string $newval: Item value or empty string (not required if $newdata is array) - :param int $expires: lifetime in seconds (0 for default) + :param int $expire: Lifetime in seconds (0 for default) :returns: void Sets items into session tempdata example:: @@ -636,10 +641,10 @@ Class Reference .. method:: unset_tempdata($item) - :param mixed $item: name of item or array of items + :param mixed $item: Item name or an array containing multiple items :returns: void - Unsets previously setted items from the tempdata. Example:: + Unsets previously set items from tempdata. Example:: $this->session->unset_tempdata('user'); //unsets 'user' from tempdata. @@ -649,10 +654,11 @@ Class Reference .. method:: tempdata($item) - :param string $item: name of tempdata item + :param string $item: Tempdata item name :returns: string - Returns a string containing the value of the passed item or NULL if the item is not found. Example:: + Returns a string containing the value of the passed item or NULL if the item is not found. + Example:: $this->session->tempdata('message'); //returns 'Test message.' considering the set_tempdata example. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 69e1b4f054521bc055af9e2b377a3a578fc6cadc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 7 Jan 2014 17:29:25 +0200 Subject: [ci skip] Add a PostgreSQL CREATE TABLE sample to the Session docs From PR #2758 --- user_guide_src/source/libraries/sessions.rst | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 4ce355606..c76bccb8c 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -400,11 +400,24 @@ session class:: KEY `last_activity_idx` (`last_activity`) ); +Or if you're using PostgreSQL:: + + CREATE TABLE ci_sessions ( + session_id varchar(40) DEFAULT '0' NOT NULL, + ip_address varchar(45) DEFAULT '0' NOT NULL, + user_agent varchar(120) NOT NULL, + last_activity bigint DEFAULT 0 NOT NULL, + user_data text NOT NULL, + PRIMARY KEY (session_id) + ); + + CREATE INDEX last_activity_idx ON ci_sessions(last_activity); + .. note:: By default the table is called ci_sessions, but you can name it anything you want as long as you update the - application/config/config.php file so that it contains the name you have - chosen. Once you have created your database table you can enable the - database option in your config.php file as follows:: + *application/config/config.php* file so that it contains the name + you have chosen. Once you have created your database table you + can enable the database option in your config.php file as follows:: $config['sess_use_database'] = TRUE; -- cgit v1.2.3-24-g4f1b From 75b3fb26a324c71ff18fa19b2a3caa357f8133ec Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Sat, 11 Jan 2014 06:58:43 -0600 Subject: cleanup warnings Signed-off-by: Connor Tumbleson --- user_guide_src/source/libraries/sessions.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index c76bccb8c..010b464d3 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -509,7 +509,6 @@ your config.php file to an array including your driver name:: $config['sess_valid_drivers'] = array('sess_driver'); - *************** Class Reference *************** @@ -536,7 +535,7 @@ Class Reference .. note:: This method should be the last one called, and even flash variables will no longer be available after it is used. - If you only want some items destroyed and not all, use + If you only want some items destroyed and not all, use ``unset_userdata()``. .. method:: sess_regenerate([$destroy = FALSE]) -- cgit v1.2.3-24-g4f1b From de1fe7d504898bc6a42e24b4c73da3887a9933d6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 20 Jan 2014 17:06:16 +0200 Subject: [ci skip] Add 'Using the X class' headings to Session & Language lib docs Fixes 2 doc compile warnings --- user_guide_src/source/libraries/sessions.rst | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 3e6dcf28b..c4f861620 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -16,6 +16,10 @@ you wish, while still taking advantage of the features of the Session class.
+*********************** +Using the Session Class +*********************** + Initializing a Session ====================== -- cgit v1.2.3-24-g4f1b From 8b9dd229bc58e271cba9665d26882d8c8449ac36 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 24 Jan 2014 14:41:22 +0200 Subject: [ci skip] Update Session library docs --- user_guide_src/source/libraries/sessions.rst | 94 ++++++++++++++++------------ 1 file changed, 53 insertions(+), 41 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index f63f584a6..9e23e9b60 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -103,6 +103,23 @@ fetch. For example, to fetch the session ID you will do this:: .. note:: The function returns NULL if the item you are trying to access does not exist. +If you want to retrieve all of the existing userdata, you can simply +omit the item key parameter:: + + $this->session->userdata(); + + /** + * Produces something similar to: + * + * Array + * ( + * [session_id] => 4a5a5dca22728fb0a84364eeb405b601 + * [ip_address] => 127.0.0.1 + * [user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; + * [last_activity] => 1303142623 + * ) + */ + Adding Custom Session Data ========================== @@ -144,23 +161,6 @@ If you want to verify that a userdata value exists, call ``has_userdata()``. $this->session->has_userdata('some_name'); -Retrieving All Session Data -=========================== - -An array of all userdata can be retrieved as follows:: - - $this->session->userdata() - -And returns an associative array like the following:: - - Array - ( - [session_id] => 4a5a5dca22728fb0a84364eeb405b601 - [ip_address] => 127.0.0.1 - [user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; - [last_activity] => 1303142623 - ) - Removing Session Data ===================== @@ -246,6 +246,10 @@ To read a tempdata variable:: $this->session->tempdata('item'); +And of course, if you want to retrieve all existing tempdata:: + + $this->session->tempdata(); + If you need to remove a tempdata value before it expires, use ``unset_tempdata()``:: @@ -550,12 +554,14 @@ Class Reference Regenerate the current session data. - .. method:: userdata($item) + .. method:: userdata([$item = NULL]) :param string $item: Session item name - :returns: string + :returns: mixed + + If no parameter is passed, it will return an associative array of all existing userdata. - Returns a string containing the value of the passed item or NULL if the item is not found. + Otherwise returns a string containing the value of the passed item or NULL if the item is not found. Example:: $this->session->userdata('user'); @@ -565,13 +571,15 @@ Class Reference :returns: array - Retruns an array with all of the session userdata items. + Returns an array with all of the session userdata items. + + .. note:: This method is DEPRECATED. Use ``userdata()`` with no parameters instead. - .. method:: all_flashdata() + .. method:: &get_userdata() :returns: array - Retruns an array with all of the session flashdata items. + Returns a reference to the userdata array. .. method:: set_userdata($newdata[, $newval = '']) @@ -607,6 +615,19 @@ Class Reference Checks if an item exists in the session. + .. method:: flashdata([$item = NULL]) + + :param string $item: Flashdata item name + :returns: mixed + + If no parameter is passed, it will return an associative array of all existing flashdata. + + Otherwise returns a string containing the value of the passed item or NULL if the item is not found. + Example:: + + $this->session->flashdata('message'); + //returns 'Test message.' considering the set_flashdata example. + .. method:: set_flashdata($newdata[, $newval = '']) :param mixed $newdata: Item name or an array of items @@ -629,16 +650,18 @@ Class Reference Keeps items into flashdata for one more request. - .. method:: flashdata($item) + .. method:: tempdata([$item = NULL]) - :param string $item: Flashdata item name - :returns: string + :param string $item: Tempdata item name + :returns: mixed - Returns a string containing the value of the passed item or NULL if the item is not found. + If no parameter is passed, it will return an associative array of all existing tempdata. + + Otherwise returns a string containing the value of the passed item or NULL if the item is not found. Example:: - $this->session->flashdata('message'); - //returns 'Test message.' considering the set_flashdata example. + $this->session->tempdata('message'); + //returns 'Test message.' considering the set_tempdata example. .. method:: set_tempdata($newdata[, $newval = ''[, $expire = 0]]) @@ -667,15 +690,4 @@ Class Reference //unsets 'user' from tempdata. $this->session->unset_tempdata(array('user', 'useremail')); - //unsets both 'user' and 'useremail' from the tempdata. - - .. method:: tempdata($item) - - :param string $item: Tempdata item name - :returns: string - - Returns a string containing the value of the passed item or NULL if the item is not found. - Example:: - - $this->session->tempdata('message'); - //returns 'Test message.' considering the set_tempdata example. + //unsets both 'user' and 'useremail' from the tempdata. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 28c2c975b118016d07212ed8e7c22ff280309f82 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 8 Feb 2014 04:27:48 +0200 Subject: [ci skip] Add return types to library docs --- user_guide_src/source/libraries/sessions.rst | 73 ++++++++++++++++------------ 1 file changed, 41 insertions(+), 32 deletions(-) (limited to 'user_guide_src/source/libraries/sessions.rst') diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 9e23e9b60..f05f86af1 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -526,20 +526,23 @@ Class Reference .. method:: load_driver($driver) - :param string $driver: Driver name - :returns: object + :param string $driver: Driver name + :returns: Instance of currently loaded session driver + :rtype: mixed Loads a session storage driver .. method:: select_driver($driver) - :param string $driver: Driver name - :returns: void + :param string $driver: Driver name + :rtype: void Selects default session storage driver. .. method:: sess_destroy() + :rtype: void + Destroys current session .. note:: This method should be the last one called, and even flash @@ -549,15 +552,16 @@ Class Reference .. method:: sess_regenerate([$destroy = FALSE]) - :param bool $destroy: Whether to destroy session data - :returns: void + :param bool $destroy: Whether to destroy session data + :rtype: void Regenerate the current session data. .. method:: userdata([$item = NULL]) - :param string $item: Session item name - :returns: mixed + :param string $item: Session item name + :returns: Item value if found, NULL if not or an array of all userdata if $item parameter is not used + :rtype: mixed If no parameter is passed, it will return an associative array of all existing userdata. @@ -569,7 +573,8 @@ Class Reference .. method:: all_userdata() - :returns: array + :returns: An array of all userdata + :rtype: array Returns an array with all of the session userdata items. @@ -577,15 +582,16 @@ Class Reference .. method:: &get_userdata() - :returns: array + :returns: A reference to the userdata array + :rtype: &array Returns a reference to the userdata array. .. method:: set_userdata($newdata[, $newval = '']) - :param mixed $newdata: Item name or array of items - :param mixed $newval: Item value or empty string (not required if $newdata is array) - :returns: void + :param mixed $newdata: Item name or array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :rtype: void Sets items into session example usages:: @@ -597,8 +603,8 @@ Class Reference .. method:: unset_userdata($item) - :param mixed $item: Item name or an array containing multiple items - :returns: void + :param mixed $item: Item name or an array containing multiple items + :rtype: void Unsets previously set items from the session. Example:: @@ -610,15 +616,17 @@ Class Reference .. method:: has_userdata($item) - :param string $item: Item name - :returns: bool + :param string $item: Item name + :returns: TRUE if item exists, FALSE if not + :rtype: bool Checks if an item exists in the session. .. method:: flashdata([$item = NULL]) - :param string $item: Flashdata item name - :returns: mixed + :param string $item: Flashdata item name + :returns: Item value if found, NULL if not or an array of all flashdata if $item parameter is not used + :rtype: mixed If no parameter is passed, it will return an associative array of all existing flashdata. @@ -630,9 +638,9 @@ Class Reference .. method:: set_flashdata($newdata[, $newval = '']) - :param mixed $newdata: Item name or an array of items - :param mixed $newval: Item value or empty string (not required if $newdata is array) - :returns: void + :param mixed $newdata: Item name or an array of items + :param mixed $newval: Item value or empty string (not required if $newdata is array) + :rtype: void Sets items into session flashdata example usages:: @@ -645,15 +653,16 @@ Class Reference .. method:: keep_flashdata($item) - :param mixed $item: Item name or an array containing multiple flashdata items - :returns: void + :param mixed $item: Item name or an array containing multiple flashdata items + :rtype: void Keeps items into flashdata for one more request. .. method:: tempdata([$item = NULL]) - :param string $item: Tempdata item name - :returns: mixed + :param string $item: Tempdata item name + :returns: Item value if found, NULL if not or an array of all tempdata if $item parameter is not used + :rtype: mixed If no parameter is passed, it will return an associative array of all existing tempdata. @@ -665,10 +674,10 @@ Class Reference .. method:: set_tempdata($newdata[, $newval = ''[, $expire = 0]]) - :param mixed $newdata: Item name or array containing multiple items - :param string $newval: Item value or empty string (not required if $newdata is array) - :param int $expire: Lifetime in seconds (0 for default) - :returns: void + :param mixed $newdata: Item name or array containing multiple items + :param string $newval: Item value or empty string (not required if $newdata is array) + :param int $expire: Lifetime in seconds (0 for default) + :rtype: void Sets items into session tempdata example:: @@ -681,8 +690,8 @@ Class Reference .. method:: unset_tempdata($item) - :param mixed $item: Item name or an array containing multiple items - :returns: void + :param mixed $item: Item name or an array containing multiple items + :rtype: void Unsets previously set items from tempdata. Example:: -- cgit v1.2.3-24-g4f1b