title: CakePHP: How to list only the Posts which have been posted by the user himself/herself (one user)
body: <p>On this page, a user would see a list of links which he himself/herself has posted, not including the rests which were posted by others. I'm in the middle of writing the function in one of my models, e.g. news</p>
  
  <p>I am trying to use the idea of a dashboard: <a href="http://nuts-and-bolts-of-cakephp.com/2008/12/16/how-to-build-a-dashboard-for-your-application-in-cakephp/" rel="nofollow">http://nuts-and-bolts-of-cakephp.com/2008/12/16/how-to-build-a-dashboard-for-your-application-in-cakephp/</a></p>
  
  <p>I created my dashboards controller as:</p>
  
  <pre><code>function index () {     
             $this-&gt;set('news', ClassRegistry::init('News')-&gt;showmy());
            }
  </code></pre>
  
  <p>// In my news::model I have a function called showmy()</p>
  
  <pre><code>function showmy() {
           $userid = $this-&gt;Session-&gt;read('Auth.User.id');
           $mynews = $this-&gt;News-&gt;find('all', array('conditions' =&gt; array('News.user_id' =&gt; '$userid')));
           $this-&gt;set('mynews', $mynews);      
      }   
  </code></pre>
  
  <p>//The error I get is as follow</p>
  
  <pre><code>Undefined property: News::$Session [APP\models\news.php, line 7]
  
  Fatal error: Call to a member function read() on a non-object in C:\...\app\models\news.php on line 7
  </code></pre>
  
  <p>I know something is terribly wrong with the showmy function, can someone shed some light how do we write the function that only retrieves the posts by one user? or if the problems are minor, correct the function above?</p>