title: How does Zend_Auth storage work?
body: <p>This is very simple. I write</p>
  
  <pre><code>$auth-&gt;getStorage()-&gt;write($user);
  </code></pre>
  
  <p>And then I want, in a separate process to load this $user, but I can't because</p>
  
  <pre><code>$user = $auth-&gt;getIdentity();
  </code></pre>
  
  <p>is empty. Didn't I just... SET it? Why does it not work? Halp?</p>
  
  <p>[EDIT 2011-04-13]</p>
  
  <p>This has been asked almost two years ago. Fact is, though, that I repeated the question in July 2010 and got a fantastic answer that I back then simply did not understand. </p>
  
  <p>Link: <a href="https://stackoverflow.com/questions/1379597/zend-auth-fails-to-write-to-storage">Zend_Auth fails to write to storage</a></p>
  
  <p>I have since built a very nice litte class that I use (sometimes with extra tweaking) in all my projects using the same storage engine as Zend_Auth but circumventing all the bad.</p>
  
  <pre><code>&lt;?php
  
  class Qapacity_Helpers_Storage {
  
      public function save($name = 'default', $data) {
  
          $session = new Zend_Session_Namespace($name);
          $session-&gt;data = $data;
  
          return true;
      }
  
      public function load($name = 'default', $part = null) {
  
          $session = new Zend_Session_Namespace($name);
  
          if (!isset($session-&gt;data))
              return null;
  
          $data = $session-&gt;data;
  
          if ($part &amp;&amp; isset($data[$part]))
              return $data[$part];
  
          return $data;
      }
  
      public function clear($name = 'default') {
  
          $session = new Zend_Session_Namespace($name);
  
          if (isset($session-&gt;data))
              unset($session-&gt;data);
  
          return true;
      }
  
  }
  
  ?&gt;
  </code></pre>