title: CakePHP $this->Auth->user("id") always return null?
body: <p>I have a function that I use to get the user id of Auth component. It works fine without use <code>return json_encode</code>. The problem is that I need this works with json_encode because I get values from ajax request. 
  Using <code>json_encode</code> it always return <code>null</code> to id and I can't understand why does it occur. The problem is with the function <code>indexAjax()</code> below.</p>
  
  <p>How could I use <code>$this-&gt;Auth-&gt;user("id")</code> with <code>json_encode</code> and it not return null ?</p>
  
  <p>Trying.</p>
  
  <pre><code>//using $this-&gt;set it works fine
  public function index() {       
                  $id = $this-&gt;Auth-&gt;user("id");                
                  $empresas = $this-&gt;Empresa-&gt;find('all', array(
                              'fields'=&gt;array("id", "nomeFantasia", "cnpj",
                                      "telefone1", "telefone2", "celular", "aberto"),
                              'conditions'=&gt;array("users_id = "=&gt; $id)            
                             ));             
                  debug($id) or die;
                  //$this-&gt;set(compact('empresas'));
      }
  
  
  
  //with json_encode always return null
   public function indexAjax() {      
                  $this-&gt;autoRender = false;
                  $id = $this-&gt;Auth-&gt;user("id");
                  $empresas = $this-&gt;Empresa-&gt;find('all', array(
                              'fields'=&gt;array("id", "nomeFantasia", "cnpj",
                                      "telefone1", "telefone2", "celular", "aberto"),
                              'conditions'=&gt;array("users_id = "=&gt; $id)            
                             ));
                  return json_encode($id);                
      }
  </code></pre>