title: Cakephp blog tutoria- comments section for individual articles
body: <p>I'm new to cakephp and recently finished the blog tutorial, now I thought about having a comments section for it. I was succesful in that part. Below is my controller.   </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function add_comment() {
  
          if ($this-&gt;request-&gt;is('post')) {
  
              $this-&gt;Comment-&gt;create();
              if ($this-&gt;Comment-&gt;save($this-&gt;request-&gt;data)) {
                  $this-&gt;Session-&gt;setFlash(__('Your comment has been saved.'));
                  $this-&gt;redirect(array('controller' =&gt; 'posts', 
                                        'action' =&gt; 'index', 
                                        'admin' =&gt; false));
              }
              $this-&gt;Session-&gt;setFlash(__('Unable to add your post.'));
          }
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>echo "&lt;h1&gt;Comments &lt;/h1&gt;";
  
  foreach ($post['Comment'] as $key =&gt; $the) {
  
  echo"&lt;div id='comment-{$post['Comment'][$key]['id']}'&gt;";
  echo "Name: ", $the['name'], '&lt;br&gt;';
  echo "Comment: ", '&lt;br /&gt;', $the['comment'], '&lt;br&gt;';
  echo '&lt;/div&gt;';
  </code></pre>
  
  <p>Adding and displaying the comment was a success. Here's the part where I'm stucked in.the code below is the continuation of the view. What it does is it renders two buttons, show and hide.</p>
  
  <pre><code>if ($this-&gt;Session-&gt;read('Auth.User')) {
      echo $this-&gt;Form-&gt;button('Show', 
               array('type' =&gt; 'button',
                     'class' =&gt; 'show_comment',
                     'data-id' =&gt; $post['Comment'][$key]['id'],
                      ));
  
      echo $this-&gt;Form-&gt;button('Hide', 
               array('type' =&gt; 'button',
                     'class' =&gt; 'hide_comment',
                     'data-id' =&gt; $post['Comment'][$key]['id'],
                     ));
  }
  </code></pre>
  
  <p><strong>main.js</strong> - below is the jquery function that hides/show the comments on click</p>
  
  <pre><code>$(document).ready(function() {
      $(".hide_comment").click(function() {
          var id = $(this).data('id');
          console.log($(this).data('id'));
          $('#comment-' + id).hide();
      });
  
      $(".show_comment").click(function() {
          var id = $(this).data('id');
          console.log($(this).data('id'));
          $('#comment-' + id).show();
      });
  });
  </code></pre>
  
  <p>what I'm trying to achieve is, when the admin is logged in he can hide or show the comments?,however once the page is reloaded/refreshed the hidden comments are showed once again. How can I make the hidden comments stay hidden until I click the show button. This is my approach in hiding/showing the comments, but I am very open to your suggestions. and is very much in need of your help thank you</p>