title: CakePHP - POST call to REST API returning null
body: <p>I have set up REST for my CakePHP and I'm having a slight problem. When calling a GET method, like view or index on my controller, or even a custom method that is GET I have no problem getting an answer. But when I try to do a POST action like add I get no output from the operation even though I can see that it reached it correctly and executed (saved to the DB).</p>
  
  <p>I have properly set up the layout file for JSON and XML output as well as the routing and the view for each output type.</p>
  
  <p>EDIT:</p>
  
  <p>Relevant code in <code>beforeFilter</code> in <code>AppController</code>:</p>
  
  <pre><code>      if ( $this-&gt;RequestHandler-&gt;isAjax() ) {
          $this-&gt;layout = 'ajax';
          $this-&gt;autoRender = false;
        } elseif  ($this-&gt;RequestHandler-&gt;isXml()) {
          $this-&gt;layout = 'default'; 
          $this-&gt;RequestHandler-&gt;respondAs('xml');
          $this-&gt;RequestHandler-&gt;renderAs($this, 'xml');
        } elseif ($this-&gt;RequestHandler-&gt;ext == 'json') { 
          $this-&gt;layout = 'default';
          $this-&gt;RequestHandler-&gt;respondAs('json');
          $this-&gt;RequestHandler-&gt;renderAs($this, 'json');
        } elseif ($this-&gt;RequestHandler-&gt;accepts('html')) {
          $this-&gt;layout = 'frontend'; 
        }
  </code></pre>
  
  <p>Code in Routes:</p>
  
  <pre><code>Router::mapResources('fonykers');
  Router::mapResources('voicenotes');
  Router::parseExtensions();
  </code></pre>
  
  <p>Relevant code in my <code>add</code> method in <code>FonykersController</code>:</p>
  
  <pre><code>$response = array('ok' =&gt; true, 'title' =&gt; 'Thank you for registering', 'msg' =&gt; 'A confirmation email has been sent to the provided email address, please click on the link in the email to complete the registration process');
  if ($this-&gt;RequestHandler-&gt;isXml()) {
    $this-&gt;set(compact('response'));
  } else if ($this-&gt;RequestHandler-&gt;ext == 'json') {
    pr('This prints');
    $this-&gt;set(compact('response')); //View not being outputted
    pr('This also prints');
  } else {
    echo json_encode($response); 
  } 
  </code></pre>
  
  <p>My view in <code>/views/fonykers/json</code></p>
  
  <pre><code>&lt;?php echo json_encode(array('response' =&gt; $response)); ?&gt;
  </code></pre>
  
  <p>My layout file for json:</p>
  
  <pre><code>&lt;?php 
  header("Pragma: no-cache"); 
  header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate"); 
  header('Content-Type: application/json'); 
  header("X-JSON: ".$content_for_layout); 
  echo $content_for_layout; 
  ?&gt;
  </code></pre>