2012-09-17 142 views
0

不工作这是我的控制器功能:多分页CakePHP中

function MarketingTaskmanagement(){ 
    /*..................................Mariya : Listing of Added Tasks , Pending Tasks and Finshed Tasks..................................*/ 
    $usrname = $this->Session->read('UserName'); 
    $emp_id = $this->Session->read('emp_id'); 

    $user_level = $emp_id; //The User Level of the Loged User........ 

    /*...................................The Tasks selects here which are Assigned to this user............................................*/ 

    $this->set('user_level', $user_level); 
    $this->paginate = array('conditions' => array('status = 0', 'assigned_to = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
    $data1 = $this->paginate('TravancoMarketing'); 
    $this->set('list_1', $data1); 

    /*...................................................END..............................................................................*/ 

    /*................................The Tasks selects here which are Added by this user(Pending Tasks)..................................*/ 

    $this->paginate = array('conditions' => array('status = 2', 'user_id = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
    $data2 = $this->paginate('TravancoMarketing'); 
    $this->set('list_2', $data2); 
    /*$this->set('list_2', '');*/ 

    /*...................................................END..............................................................................*/ 

    /*...................................The Tasks selects here which are Added by this user..............................................*/ 

    $this->paginate = array('conditions' => array('status = 0', 'user_id = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
    $data3 = $this->paginate('TravancoMarketing'); 
    $this->set('list_3', $data3);/*$this->set('list_3', '');*/ 

    /*...................................................END..............................................................................*/ 

    /*...................................The Tasks selects here which are Added by this user..............................................*/ 

    $this->paginate = array('conditions' => array('status = 1', 'user_id = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
    $data4 = $this->paginate('TravancoMarketing'); 
    $this->set('list_4', $data4);/*$this->set('list_3', '');*/ 

    /*...................................................END..............................................................................*/ 

    $this->render('Marketing/taskmanagement'); 
    } 

这是我的看法页:

<?php echo $this->Html->script('jquery.min.js');?> 
<?php echo $this->Html->script('popup.js');?> 
<?php echo $this->Html->css('forms'); ?> 
<script type="text/javascript"> 
    function go_add_tasks(){ 
     //alert(1); 
     window.location = "http://localhost/works/cakephp/Travanco/TravancoMarketing/MarketingAddtask" 
    } 
</script> 
<div class="marketingcls"> 
    <div class="slabdiv"> 
     <div class="market-head"> 
      <h2 align="center">Welcome To Task Management</h2> 

     </div> 

     <? echo $this->element("marketinghead"); ?> 
     <div style="width:1125px; height:auto; border:0px solid #999999; float:left; margin:50px;"> 
     <?php 
     //$user_level = 2; 
     if($user_level != 1){ 
     ?> 

      <table width="100%" style="border:1px solid;" cellpadding="0" cellspacing="0"> 
       <tr> 
       <th scope="col" align="left">Assigned Tasks...</th> 
       </tr> 
       <?php 
       /*...................................The Tasks selects here which are Assigned to this user............................................*/ 
       if($list_1){ 
       $i=0; 
       foreach($list_1 as $row1){ 
        $assigned_id = $row1['TravancoMarketing']['id']; 
       ?> 
       <tr> 
       <td> 
       <?php echo $row1['TravancoMarketing']['title'];?> 
       <input type="hidden" name="assigned_task_id" id="assigned_task_id_<?php echo $i;?>" value="<?php echo $row1['TravancoMarketing']['id'];?>" /> 
       <?php echo $this->Html->link('...View More', '/TravancoMarketing/MarketingAssignedtask/'.$assigned_id, array('class'=>'textlinkclass', 'target'=>'_self')); ?> 
       </td> 
       </tr> 
       <?php 
       } 
       } 
       ?> 
       <tr> 
        <td> 
         <?php echo $this->paginator->numbers(); ?> 
        </td> 
       </tr> 

      </table> 
     <?php 
     } 
     ?> 
<br /> 
<?php //print_r($list);?> 
      <table cellpadding="0" cellspacing="0" border="1" width="100%"> 
       <tr> 
       <th width="34%">Set Task 
       <input type="button" name="btnaddtask" id="btnaddtask" style="width:70px; height:30px; font-family:Arial, Helvetica, sans-serif; font-size:12px; font-weight:normal; float:right; margin-right:30px; cursor:pointer; " value="Add Task" onclick="return go_add_tasks();" /> 
       <!--<input type="button" name="btnaddtask" id="btnaddtask" style="width:70px; height:30px; font-family:Arial, Helvetica, sans-serif; font-size:12px; font-weight:normal; float:right; margin-right:30px; cursor:pointer; " value="Add Task" onclick="return pop_add_task_frm_other();" />-->   </th> 
       <th width="35%">Review Task</th> 
       <th width="31%">Finished Task</th> 
       </tr> 
       <tr> 
       <td> 
        <table border="1" style="width:100%;" cellpadding="0" cellspacing="0"> 
           <?php 
           /*...................................The Tasks selects here which are Added by this user..............................................*/ 
           if($list_3){ 
           $i=0; 
           foreach($list_3 as $row3){ 
           $added_id = $row3['TravancoMarketing']['id']; 
           ?> 
            <tr> 
            <td><?php echo $row3['TravancoMarketing']['title'];?> 
            <input type="hidden" name="set_task_id" id="set_task_id_<?php echo $i;?>" value="<?php echo $row3['TravancoMarketing']['id'];?>" /> 

            <?php echo $this->Html->link('...View More', '/TravancoMarketing/MarketingListaddedtask/'.$added_id, array('class'=>'textlinkclass', 'target'=>'_self')); ?> 
            </td> 
            </tr> 
           <?php 
           $i++; 
           } ?> 
           <tr> 
         <?php echo $this->paginator->numbers(); ?> 


         </td> 
         </tr> 
         <?php } ?> 
        </table> 

         </td> 
         <td> 
         <table border="1" style="width:100%;" cellpadding="0" cellspacing="0"> 
           <?php 
           /*................................The Tasks selects here which are Added by this user(Pending Tasks)..................................*/ 
           $i=0; 
           if($list_2){ 
           foreach($list_2 as $row2){ 
           $review_id = $row2['TravancoMarketing']['id']; 
           ?> 
            <tr> 
            <td><?php echo $row2['TravancoMarketing']['title'];?> 
            <input type="hidden" name="review_task_id" id="review_task_id_<?php echo $i;?>" value="<?php echo $row2['TravancoMarketing']['id'];?>" /> 
            <?php echo $this->Html->link('...View More', '/TravancoMarketing/MarketingListpendingtask/'.$review_id, array('class'=>'textlinkclass', 'target'=>'_self')); ?> 
            </td> 
            </tr> 
           <?php 
           $i++; 
           } ?> 
           <tr> 
         <td> 
          <?php echo $this->paginator->numbers(); ?> 
         </td> 
         </tr> 
         <?php } ?> 
        </table> 



       </td> 
       <td> 
        <table border="1" style="width:100%;" cellpadding="0" cellspacing="0"> 
           <?php 
           /*...............................The Tasks selects here which are Added by this user(Finished Tasks).................................*/ 
           $i=0; 
           if($list_4){ 
           foreach($list_4 as $row4){ 
           $review_id = $row4['TravancoMarketing']['id']; 
           ?> 
            <tr> 
            <td><?php echo $row4['TravancoMarketing']['title'];?> 
            <input type="hidden" name="review_task_id" id="review_task_id_<?php echo $i;?>" value="<?php echo $row4['TravancoMarketing']['id'];?>" /> 
            <?php echo $this->Html->link('...View More', '/TravancoMarketing/MarketingListfinishedtask/'.$review_id, array('class'=>'textlinkclass', 'target'=>'_self')); ?> 
            </td> 
            </tr> 
           <?php 
           $i++; 
           } ?> 
           <tr> 
         <td> 
          <?php echo $this->paginator->numbers(); ?> 
         </td> 
         </tr> 
         <?php } ?> 
        </table> 
       </td> 
       </tr> 
      </table> 

     </div> 
    </div> 
</div> 

有没有分页链接displaying.this是屏幕截图。 enter image description here

但是,当我在控制器命令代码为这样的:

`/*...................................The Tasks selects here which are Added by this user..............................................*/ 

$this->paginate = array('conditions' => array('status = 1', 'user_id = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
$data4 = $this->paginate('TravancoMarketing'); 
$this->set('list_4', $data4);/*$this->set('list_3', '');*/ 

/*...................................................END..............................................................................*/ 

/*...................................The Tasks selects here which are Added by this user..............................................*/ 

$this->paginate = array('conditions' => array('status = 0', 'user_id = '.$user_level), 'limit' => 3, 'order' => array('TravancoMarketing.id' => 'DESC')); 
$data3 = $this->paginate('TravancoMarketing'); 
$this->set('list_3', $data3);/*$this->set('list_3', '');*/ 

/*...................................................END..............................................................................*/` 

$this->render('Marketing/taskmanagement'); 

Then it will displays pagination in all section ,but that pagination not correct ,that means the pagination count is correct only for first section in this time.. 

这是chaing代码的订单后的截图: enter image description here 那么,什么是我的代码的问题.. ..

The pagination is not working correctly in my view page. 

It take the pagination links of last executed query and put this link for all section .This is the main problem in my code. 

How can i solve this? 
+0

请使用我的方法解释[这里] [1] [1]:http://stackoverflow.com/a/21211278/2486198 – Mitja

回答

0

不幸的是,我相信这不是技术上可以使用内置的分页进行分页单页上多个模型,因为那里是没有办法的CAK ePHP实际上知道要分页的具体模型,因为来自paginator助手的所有链接都以/controller/action/page:1的形式出现 - 而CakePHP无法知道page1与哪个模型相关。

我个人建议采取ajax方法。

+0

我怎样才能做到这一点......? – Kichu

+0

不幸的是,这是一项相当艰巨的任务,您需要为每个要分页的模型设置和操作,为该模型分页,然后更改分页链接以使用Ajax添加新操作(可以删除原始分页呼叫并将其替换为您的“MarketingTaskmanagement”操作中的查找。 – Dunhamzzz