using $_SESSION variables and organizing your data however you want
You are using $_SESSION variables, just not directly. And by using namespaces, you are organizing however you want.
Zend wants you to use their syntax to set session variables in separate sub-arrays
It would defeat the purpose of using Zend_Session if you don't use their class methods to manipulate the session variables.
I have been forced to commit those session variables to Zend_Registry values (have to be set for each page load, but are available to all files within your M/V/C framework).
Using the registry is fairly normal for this. However, you can also create your own static class to act as a repository for your session namespace(s), which can be summoned from any page.
If you aren't using the registry (which is a static class to store variables), then you are probably creating multiple instances of the same session namespace, which can lead to confusion and the wrong data being stored / retrieved. Additionally, since locks and such are stored in the instance (not the session variables themselves), if you set a lock in one instance, the other(s) don't know about it and will still modify the value.
So basically, I now have to initialize the session variables and commit them to Zend_Registry values for EVERY page load via the bootstrap file.
Ummm, you have to do with with normal sessions anyway...session_start(). Using Zend_Session you're just using "$session = new Zend_Session_Namespace('yournamespace', true)".
This is retarded. Absolutely retarded.
I'm sorry you think so.
Namespacing the session is actually quite good for security purposes. Probably the most common thing to store in a session is whether a user is authenticated or not....e.g. "$_SESSION['authenticated'] = true". Well, imagine you have other applications running on your server that require authentication to access. If they all use the above $_SESSION['authenticated'] to determine if the user should be allowed access, then when the user logs into one, they are logged into them all...even applications that they may not actually have access to (remember session data is separated on the server by domain names...not path to the file requesting session data...so if all of your apps are on
www.myserver.com, then they all share a $_SESSION array).
If you are using Zend_Session and creating a namespace for each application, then you don't have to worry about that...
Application1:
$session = new Zend_Session_Namespace('application1', true);
if ($session->isAuthenticated == true) {
...
}Application2:
$session = new Zend_Session_Namespace('application2', true);
if ($session->isAuthenticated == true) {
...
}This allows you to reuse your authentication methods...you simply pass Zend_Auth the session namespace as it's storage adaptor and it will store the auth data in the namespace. So now, all of your applications can use the same authentication code, without fear of cross application authentication.
Application1 bootstrap:
// create the namespace for this app
$session = new Zend_Session_Namespace('application1', true);
// get our authentication, which is an extension of Zend_Auth
// The intention here is to write a reusable single class to authenticate your users, say against your
// local Active Directory domain, which is then used by all applications...users only have one
// username and password for all applications......
$auth = My_General_Purpose_Code_Library_Authentication::getInstance();
// make this applications auth code use the namespace for this application
// Zend_Auth will, by default, use the Zend_Auth namespace, but this defeats the purpose
// of namespacing to protect against cross application authentication
$auth->setStorage($session);
Application1 Authentication controller:
// This isn't a full example of how to use Zend_Auth, but you get the point...
$auth = My_General_Purpose_Code_Library_Authentication::getInstance();
$auth->username = $_POST['username'];
$auth->password = $_POST['password'];
// do authentication, which stores the result in our namespace
$auth->authenticate();Using the above, you can now check to see if the user is authenticated from any other place in your application
Application1 Someother Controller:
// get the auth instance
$auth = My_General_Purpose_Code_Library_Authentication::getInstance();
if (!$auth->hasIdentity()) {
// user is not authenticated
$this->_redirect('auth', 'login');
}