Of all the docs I've found (and devoured) on Zend Framework 1.5's Session namespaces, I cannot find anything on how to access a namespace once you're directed to another script.

Example:
in your Auth class, you authenticate the user, start the session, create the namespace, add values to the namespace and then redirect the user to the index page. From the index page, I am trying everything under the sun to access the values I applied to the namespace in the AuthController class and am having no luck

From my auth class:

// initiate sessions
require_once 'Zend/Session.php';
Zend_Session::start();
require_once 'Zend/Session/Namespace.php';

// processing and validation logic

// namespace assignment
$authNamespace = new Zend_Session_Namespace('Zend_Auth');			
$authNamespace->setExpirationSeconds(720);
$authNamespace->userID = $employeeData->id;
$authNamespace->fName = $employeeData->sFName;
$authNamespace->lName = $employeeData->sLName;
$authNamespace->email = $employeeData->sEmail;

$this->_redirect('/');

Once the user is redirected, I am initiating the session within the bootstrap file.
Within my layout file (layout.phtml) I am doing the following with no luck:
From the bootstrap file (index.php):

// initiate sessions
require_once 'Zend/Session.php';
Zend_Session::start();

require_once 'Zend/Session/Namespace.php';
$authNamespace = new Zend_Session_Namespace('Zend_Auth');

From layout.phtml (output wrapper for all files, excluding login script)

<p id="logged-in">Logged in as <?php echo $this->escape($authNamespace->fName . ' ' . $this->escape($authNamespace->lName));?>.

What am I missing here?

    I haven't got a test environment handy and nothing's jumping out at me, but I do note that:

    Namespace names are restricted to character sequences represented as non-empty PHP strings that do not begin with an underscore ("_") character. Only core components included in the Zend Framework should use namespace names starting with "Zend".

      The initial code for initializing the session namespace came from the zend framework manual.

      I tried changing 'Zend_Auth' to 'authNamespace' with the same results as before.

      This is why I hate being a semi-early adopter - lack of forum posts from others who already had my issues ;-)

        echo-ing out $authNamespace->getIdentity() returns the username used to log into the LDAP server.

        the following is the result of a print_r on $authNamespace:

        Zend_Auth Object
        (
            [_storage:protected] => Zend_Auth_Storage_Session Object
                (
                    [_session:protected] => Zend_Session_Namespace Object
                        (
                            [_namespace:protected] => Zend_Auth
                        )
        
                [_namespace:protected] => Zend_Auth
                [_member:protected] => storage
            )
        
        )

          Ok - I figured it out.

          Lete me start this with my opinion on how Zend handled this. It's absolutely ridiculous. Rather than using $_SESSION variables and organizing your data however you want, Zend wants you to use their syntax to set session variables in separate sub-arrays. Given that, these session variables are NOT available to any/all script in your M/V/C files.

          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).

          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.

          This is retarded. Absolutely retarded.

          I am honestly hoping and wishing that someone can come along and say 'Hey, Zend did this for this and that reason and here's a smorgasbord of benefits from doing so.

          It's a great wish, but somehow I doubt anyone will be able to find benefits that outweigh the cons here.

            2 months later

            I had the same problem (stored session values, than a redirect, no stored session values). Calling the static method Zend_Session::writeClose() resulted in an exception so I fell back to the php method session_write_close()

            Problem fixed...

              Write a Reply...