2012-05-05 42 views
1

我已經作出的一種方法,其將利用用戶界面選項卡的jquery多個AJAX分頁爲CakePHP中

function debate_view_commenttab_content(){ 
     $this->autoRender = false; 
     $this->layout=null;  
     if($this->RequestHandler->isAjax()) 
     { 

       if (!empty($this->passedArgs['debateId'])) { 
        $debateId=$this->passedArgs['debateId']; 
        $this->set('debateId',$debateId); 
        $this->DebatePost->recursive = 0;     

        if (!empty($this->passedArgs['greensideupdateId'])) { 
         $this->set('greensideupdateId', $this->passedArgs['greensideupdateId']); 
        }else{ 
         $this->set('greensideupdateId', 'greensideupdateId'); 
        } 
        if (!empty($this->passedArgs['redsideupdateId'])) { 
         $this->set('redsideupdateId', $this->passedArgs['redsideupdateId']); 
        }else{ 
         $this->set('redsideupdateId', 'redsideupdateId'); 
        } 

       $arrfavdebatecomment=$this->get_infavour_records($debateId);        
       $this->set('arrfavdebatecomment',$arrfavdebatecomment);         


       $arragndebatecomment=$this->get_against_records($debateId);     
       $this->set('arragndebatecomment',$arragndebatecomment);         


       if(!empty($this->passedArgs['paginatedrecord']) && $this->passedArgs['paginatedrecord']==1 && $this->passedArgs['greensideupdateId']=='greensideupdateId'){ 

         $this->render('/elements/debate_posts/append_page_record'); 

       }else if(!empty($this->passedArgs['paginatedrecord']) && $this->passedArgs['paginatedrecord']==1 && $this->passedArgs['redsideupdateId']=='redsideupdateId'){ 

         $this->render('/elements/debate_posts/append_page_record_against'); 

       }else{ 

        $this->render('/elements/debate_posts/commnts_tab_content');   
       }  

       } 
     } 
    } 

現在從上面的方法我稱兩個功能是作爲被稱爲單模型和控制器在同一頁上下面:

function get_infavour_records($debateId=Null){ 


     $this->DebateComment->recursive = 0;                 
     $favconditions = array('DebateComment.debate_id'=>$debateId,'DebateComment.debate_type'=>'in favour','DebateComment.status'=>'Active'); 
     $this->paginate['DebateComment'] = array(
      'limit' => 1,//Configure::read('CommentSetting.show_no_default_comments'),     
      'recursive'=>-1 
      ); 
     $arrfavdebatecomment=$this->paginate('DebateComment',$favconditions); 

     $this->helpers['Paginator'] = array('ajax' => 'Ajax'); 
     return $arrfavdebatecomment; 

    } 

     function get_against_records($debateId=Null){ 
      $this->DebateComment->recursive = 0;                 
      $agnconditions = array('DebateComment.debate_id'=>$debateId,'DebateComment.debate_type'=>'against','DebateComment.status'=>'Active'); 

       $this->paginate['DebateComment'] = array(
       'limit' => Configure::read('CommentSetting.show_no_default_comments'), 
       'recursive'=>-1 
       );     
       $arragndebatecomment=$this->paginate('DebateComment',$agnconditions); 
       $this->helpers['Paginator'] = array('ajax' => 'Ajax'); 
       return $arragndebatecomment; 
    } 
現在

上append_page_record.ctp的觀看側我寫:

<?php  $this->Paginator->options(array(
      'update' => '#'.$greensideupdateId, 
      'evalScripts' => true, 
      'before' => $this->Js->get('#spinner')->effect('fadeIn', array('buffer' => false)), 
      'complete' => $this->Js->get('#spinner')->effect('fadeOut', array('buffer' => false)), 
      'url' => array('controller' => 'debate_posts','action'=>'debate_view_commenttab_content','debateId'=>$debateId,'greensideupdateId' => $greensideupdateId,'paginatedrecord' => 1), 
     )); 

     echo '<div class="members_prew_next_area cf"><div class="pagination_area">'.$this->Paginator->first('first').$this->Paginator->prev('<<', array('escape' => false), null, array('class'=>'disabled','escape' => false)).$this->Paginator->numbers(array('before'=>'','after'=>'','model'=>'','modulus'=>'','separator'=>'')).$this->Paginator->next('>>', array('escape' => false), null, array('class' => 'disabled','escape' => false)).$this->Paginator->last('last'); 
     echo $js->writeBuffer(); 
     echo ' </div></div>'; 


       if($arrfavdebatecomment){   
       echo '<div class="clear"><ul class="cf">'; 
       $i = 0;      
       foreach ($arrfavdebatecomment as $favrecord): 

       echo '<li>'.'<h2>'.($favrecord['DebateComment']['debate_comment_title']).'</h2></li>'; 

       endforeach; 
       echo '</ul>'; 
       echo '</div>'; 
       }else{ 
        __l("No record"); 
       } 


     ?> 

和append_page_record_against.ctp

<?php $this->Paginator->options(array(
      'update' => '#'.$redsideupdateId, 
      'evalScripts' => true, 
      'before' => $this->Js->get('#spinner')->effect('fadeIn', array('buffer' => false)), 
      'complete' => $this->Js->get('#spinner')->effect('fadeOut', array('buffer' => false)),    
      'url' => array('controller' => 'debate_posts','action'=>'debate_view_commenttab_content','debateId'=>$debateId,'redsideupdateId' => $redsideupdateId,'paginatedrecord' => 1), 
     )); 

     echo '<div class="members_prew_next_area cf"><div class="pagination_area">'.$this->Paginator->first('first').$this->Paginator->prev('<<', array('escape' => false), null, array('class'=>'disabled','escape' => false)).$this->Paginator->numbers(array('before'=>'','after'=>'','model'=>'','modulus'=>'','separator'=>'')).$this->Paginator->next('>>', array('escape' => false), null, array('class' => 'disabled','escape' => false)).$this->Paginator->last('last'); 
     echo $js->writeBuffer(); 
     echo ' </div></div>'; 


       if($arragndebatecomment){   
       echo '<div class="clear"><ul class="cf">'; 
       $i = 0;      
       foreach ($arragndebatecomment as $record): 

       echo '<li>'.'<h2>'.($record['DebateComment']['debate_comment_title']).'</h2></li>'; 

       endforeach; 
       echo '</ul>'; 
       echo '</div>'; 
       }else{ 
        __l("No record"); 
       } 


     ?> 

現在,當我運行我的標籤方法,它顯示了同樣的分頁欄兩次兩者的結果,而不是不同的着我同時顯示使用分頁和分頁程序同一頁上的分頁?如果你能幫助我,請做它需要。

回答

0

如果我沒有記錯的話,當你分頁模型,它保存的默認值/選項/設置在:

$this->params['paging'][<ModelName>] 

因此,如果您分頁同型號的兩倍,它覆蓋了前代機型的默認/選項/設置。

我目前正在處理一個類似的問題,目前我唯一想到的解決方法是首先動態更新每個div(通過Ajax),以便每個請求的索引都可以在$ this-> params ['paging']存儲默認值/選項/設置。