2010-07-28 61 views
0

請參見下面的代碼snippt:在CakePHP中,佈局調用兩次當我使用AJAX

<?php 
    //Sets the update and indicator elements by DOM ID 
    $paginator->options(array('update' => 'content','indicator' => 'spinner','url' =>$this->passedArgs)); 

    echo $paginator->prev('<< Previous', null, null, array('class' => 'disabled')); 
    echo $paginator->next('Next >>', null, null, array('class' => 'disabled')); 
?> 

我的網址爲http://total.projectsjunction.com/artists/portfolios/1

現在我有一個疑難問題。我使用基於AJAX的尋呼與cakePHP但是當我點擊下一頁它調用頁眉和頁腳兩次。

如何我只能調用佈局一次,如果我使用函數兩次與Ajax。

請給予支持。

感謝

回答

0

像這樣的東西可以幫助你:

if($this->RequestHandler->isAjax()) { 
    $this->layout = false; 
} 

這將關閉佈局上的一個Ajax請求,但離開它,否則。我相信這會針對特定的請求,但我沒有測試過,也沒有必要親自去做。

0

試試這個在beforeFilter()函數,我相信你的問題將得到解決.....

if ($this->RequestHandler->isAjax()) 
    { 
     Configure::write('debug',0); 
     $this->header('Pragma: no-cache'); 
     $this->header('Cache-control: no-cache'); 
     $this->autoRender = false; 
     $this->autoLayout = false; 
     /* 
      for disable layout you can also use 
      $this->layout=''; 
      $this->layout=false; 

     */ 

    }