title: CakePHP: Can't get logged in user's group ID using Auth and Session
body: <p>I am a beginner with CakePHP trying to build my first app.</p>
  
  <p>I have the following login code:</p>
  
  <pre><code>function login() {
      if ($this-&gt;Session-&gt;read('Auth.User')) {
  
          $result = $this-&gt;User-&gt;find('first', array(
              'conditions' =&gt; array(
                  'User.id' =&gt; $this-&gt;Auth-&gt;user('id')
              ),
              'fields' =&gt; 'Group.id'
          ));
          $groupId = $result['Group']['id'];
          $this-&gt;Session-&gt;write('Auth.Group.id', $groupId);
          $this-&gt;Session-&gt;setFlash('You are logged in with Group ID ' . $groupId . '!', 'auth');
      }
  }
  </code></pre>
  
  <p>So as you can see, I am setting the <code>Auth.Group.id</code> session variable, as well as the <code>auth flash</code>.</p>
  
  <p>However, in my <code>app/views/layouts/default.ctp</code>, when I</p>
  
  <pre><code>&lt;?php echo $session-&gt;flash() ?&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;?php echo $session-&gt;flash('auth') ?&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;?php echo 'ID=' . $session-&gt;read('Auth.Group.id'); ?&gt;
  </code></pre>
  
  <p>I get nothing. What am I doing wrong here?</p>
  
  <p>EDIT: here is my AppController</p>
  
  <pre><code>class AppController extends Controller {
      var $components = array('Acl', 'Session', 'Auth');
  
      function beforeFilter() {
          //Configure AuthComponent
          $this-&gt;Auth-&gt;actionPath = 'controllers/';
          $this-&gt;Auth-&gt;authorize = 'actions';
          $this-&gt;Auth-&gt;loginAction = array('controller' =&gt; 'users', 'action' =&gt; 'login');
          $this-&gt;Auth-&gt;logoutRedirect = array('controller' =&gt; 'users', 'action' =&gt; 'login');
          $this-&gt;Auth-&gt;fields = array('username' =&gt; 'email', 'password' =&gt; 'password');
          $this-&gt;Auth-&gt;allowedActions = array('display','logout','login');
      }
  </code></pre>