Basic UsageZend_Session_Namespace instances provide the primary API for manipulating session data in the Zend Framework. Namespaces are used to segregate all session data, although a default namespace exists for those who only want one namespace for all their session data. Zend_Session utilizes ext/session and its special $_SESSION superglobal as the storage mechanism for session state data. while $_SESSION is still available in PHP's global namespace, developers should refrain from directly accessing it, so that Zend_Session and Zend_Session_Namespace can most effectively and securely provide its suite of session related functionality. Each instance of Zend_Session_Namespace corresponds to an entry of the $_SESSION superglobal array, where the namespace is used as the key.
It is possible to use Zend_Session in conjunction with other code that uses $_SESSION directly. To avoid problems, however, it is highly recommended that such code only uses parts of $_SESSION that do not correspond to instances of Zend_Session_Namespace. Tutorial Examples
If no namespace is specified when instantiating
Zend_Session_Namespace, all data will be transparently stored in
a namespace called " Example #1 Counting Page Views
When multiple modules use instances of Zend_Session_Namespace having different namespaces, each module obtains data encapsulation for its session data. The Zend_Session_Namespace constructor can be passed an optional $namespace argument, which allows developers to partition session data into separate namespaces. Namespacing provides an effective and popular way to secure session state data against changes due to accidental naming collisions.
Namespace names are restricted to character sequences represented as non-empty
PHP strings that do not begin with an underscore (" Example #2 New Way: Namespaces Avoid Collisions
The example above achieves the same effect as the code below, except that the session objects above preserve encapsulation of session data within their respective namespaces. Example #3 Old Way: PHP Session Access
Iterating Over Session Namespaces
Zend_Session_Namespace provides the full » IteratorAggregate
interface, including support for the Example #4 Session Iteration
Accessors for Session NamespacesZend_Session_Namespace implements the __get(), __set(), __isset(), and __unset() » magic methods, which should not be invoked directly, except from within a subclass. Instead, the normal operators automatically invoke these methods, such as in the following example: Example #5 Accessing Session Data
|