title: CakePHP: Accessing session data from within a controller
body: <p>I have an edit action in the users controller. What I want to do is redirect anyone to a different action if their Auth.User.id does not equal the id of the user they are trying to edit. </p>
  
  <p>I can access variables in my views like this:</p>
  
  <pre><code>if($session-&gt;read('Auth.User.id') != $id){
  </code></pre>
  
  <p>but this doesn't work in my controller. Getting:</p>
  
  <pre><code>Undefined variable: session
  </code></pre>
  
  <p>How do I access session data within a controller? also, if any has a better way of achieving what I want to do, feel free to add!</p>
  
  <p>Thanks,</p>
  
  <p>Jonesy</p>