2012-05-05 4 views
1

Я сделал один метод, который будет вызываться с помощью вкладки интерфейса JQueryMultiple Аякса нумерация страниц для одной модели и контроллера на ту же странице в 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"); 
       } 


     ?> 

Теперь, когда я бег моего метода вкладки он показывает тот же постраничный бар дважды для обоего результатов вместо различного ханжества я показать как пагинацию на одной странице с помощью постраничной и Paginator? Пожалуйста, сделайте это нужным, если вы можете мне помочь.

ответ

0

Если я не ошибаюсь, когда вы постраничной модель, она сохраняет значения по умолчанию/параметры/настройки в:

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

Поэтому, если вы постраничной ту же модель дважды, он переписывает по умолчанию предыдущей модели/опции/настройки.

В настоящее время я имею дело с подобной проблемой, и единственная работа, о которой я думал, заключалась в том, чтобы динамически обновлять (через Ajax) каждый div сначала, так что каждый запрос имеет индекс, доступный в $ this-> params ['paging'], чтобы сохранить настройки по умолчанию/параметры/настройки.