Cake PHP Ajax布局缓存

After any ajax request all subsequent non ajax request is returning with ajax layout instead of default layout.

Obs:

  • Ocurrs only on production enviroment.
  • Configure::write('Cache.disable', true); // Don't have any effect!
  • Cake Version 2.4.4
  • After 20 ~ 30 seconds the layout (default) is rendered.
  • config/core.php is identical.

I don't no why , and i loose 8 hours on that, any tip?

The controller (But any ajax on any controller cause the problem:

<?php

App::uses('AppController', 'Controller');

class NewslettersController extends AppController
{

public $paginate = array(
    'limit' => 20,
    'paramType' => 'querystring',
    'order' => array(
        'Newsletter.created' => 'DESC'
    )
);

public function beforeFilter()
{
    parent::beforeFilter();
    $this->Auth->allow(array('add','push'));
}

public function admin_index()
{
    $this->set('dataGrid', $this->paginate('Newsletter'));
}

public function admin_view($id = null)
{
    $this->Newsletter->id = $id;
    $result = $this->Newsletter->read();
    if (!$result) {
        $this->setFlashMessage('Cadastro não encontrado', 'error', array('action' => 'index'));
        return false;
    }

    $this->set('dataGrid', $result);
}

public function admin_delete($id = null)
{
    $this->Newsletter->id = $id;

    if (!$this->Newsletter->exists()) {
        $this->Session->setFlash('O item solicitado não foi encontrado!', 'alert_error');
        $this->setFlashMessage('O item solicitado não foi encontrado!', 'error', array('action' => 'index'));
    }

    try {
        if ($this->Newsletter->delete($id, false)) {
            $this->setFlashMessage('Item excluído com sucesso!', 'success', array('action' => 'index'));
        }
    } catch (Exception $e) {
        $this->setFlashMessage('Não foi possivel excluir este item pois existem itens atrelados a ele', 'error', array('action' => 'index'));
    }
}

public function admin_search()
{
    $this->autoRender = false;
    $conditions = null;
    if (isset($this->request->query['search']) && !empty($this->request->query['search'])) {
        $conditions[] = array(
            'OR' => array(
                'Newsletter.name LIKE' => '%' . $this->request->query['search'] . '%',
                'Newsletter.email LIKE' => '%' . $this->request->query['search'] . '%',
            )
        );
        $this->paginate['conditions'] = $conditions;
        $this->set('dataGrid', $this->paginate());
        $this->render('admin_index');
    }
}

//######################
//# FRONTEND           #
//######################

public function push()
{

    if($this->Newsletter->save($this->request->data))
    {
        $response = array("result"=>true,"id"=>$this->Newsletter->id);
    }
    else
    {
        $response = array("result"=>false,"errors"=>$this->Newsletter->validationErrors);
    }

    return new CakeResponse(array("body" => json_encode($response),"type" => "json"));

}

}

?>

You have to differentiate the layout for ajax in the method, please the following changes I made in the above code:

...
class NewslettersController extends AppController
{

   public layout = 'default';
...

   public function push() // if this is ajax function
   {
      $this->layout = 'ajax'; //put this for ajax functions only
      ....
   }

...
}

Hope it helps!