• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

cakephp分页功能,paginate联表查询

未分类 小杰 3年前 (2015-10-09) 137次浏览 未收录 0个评论

PHP部分:

function praise_detail($main_id){
$joins = array(array(
‘table’ => ‘comment_praises’,
‘alias’ => ‘CommentPraise’,        
‘type’ => ‘INNER’,        
‘conditions’ => array(‘CommentPraise.comment_task_id = CommentTask.id’)
));
$fields = array(‘CommentPraise.*’,’CommentTask.*’);

$this->paginate = array(‘fields’=>$fields,’conditions’=>array(‘CommentPraise.main_task_id’=>$main_id),’joins’=>$joins,’order’=>’CommentPraise.id ‘,’limit’=>50);
// var_dump(‘praise_detail’);var_dump($this->paginate());
$this->set(‘tasks’, $this->paginate());

}

praise_detail.ctp

<div class=”user index”>
    <h2><?php __(‘子任务列表’);?>-<?php echo $main_info[‘CommentTask’][‘name’];?></h2>

<table cellpadding=”0″ cellspacing=”0″ style=”/*table-layout:fixed;word-wap:break-word*/”>
<tr>
       <th><?php echo $this->Paginator->sort(‘id’);?></th>
            <th><?php echo $this->Paginator->sort(‘main_task_id’);?></th>
<th><?php echo $this->Paginator->sort(‘bid’);?></th>
<th><?php echo $this->Paginator->sort(‘uid’);?></th>
<th><?php echo $this->Paginator->sort(‘content_id’);?></th>
<th><?php echo $this->Paginator->sort(‘status’);?></th>
<th><?php echo $this->Paginator->sort(‘praise_time’);?></th>
<th><?php echo $this->Paginator->sort(‘created’);?></th>
            <th><?php echo $this->Paginator->sort(‘comment_url’);?></th>
<th class=”actions”>操作</th>
</tr>
<?php
$i = 0;
foreach ($tasks as $task):
$class = null;
if ($i++ % 2 == 0) {
$class = ‘ class=”altrow”‘;
}
?>
<tr<?php echo $class;?>>
<td><?php echo $task[‘CommentPraise’][‘id’] ?>&nbsp;</td>
<td><?php echo $task[‘CommentPraise’][‘main_task_id’]; ?>&nbsp;</td>
        <td><?php echo $task[‘CommentTask’][‘bid’]; ?>&nbsp;</td>
<td><?php echo $task[‘CommentTask’][‘uid’]; ?>&nbsp;</td>
<td><?php echo $task[‘CommentTask’][‘content_id’]; ?>&nbsp;</td>
<td><?php 
if($task[‘CommentPraise’][‘status’]==0) {
echo ‘未处理’;
}else if($task[‘CommentPraise’][‘status’]==1) {
echo ‘成功’;
}else{
echo ‘失败’;
} ?>&nbsp;</td>
<td><?php echo $task[‘CommentPraise’][‘praise_time’]?>&nbsp; </td>
<td><?php echo $task[‘CommentPraise’][‘created’]; ?>&nbsp;</td>
        <td><?php echo $task[‘CommentTask’][‘comment_url’]; ?>&nbsp;</td>
<td class=”actions”>
<?php
   if($task[‘CommentPraise’][‘status’] != 1)
   {
               // echo $this->Html->link(__(‘Delete’, true), array(‘action’ => ‘delete’, $task[‘CommentTask’][‘id’]), null, sprintf(__(‘Are you sure you want to delete # %s?’, true), $task[‘CommentTask’][‘id’]));
   }
?>
</td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
‘format’ => __(‘Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%’, true)
));
?> </p>

<div class=”paging”>
<?php echo $this->Paginator->prev(‘<< ‘ . __(‘previous’, true), array(), null, array(‘class’=>’disabled’));?>
| <?php echo $this->Paginator->numbers();?>
 |
<?php echo $this->Paginator->next(__(‘next’, true) . ‘ >>’, array(), null, array(‘class’ => ‘disabled’));?>
<?php __(‘Page To’);?>: <input type=’text’ id=’page’ class=’jump’ onkeypress=’enter_jump(“/brush/comment_tasks/praise_detail/”)’ /><?php __(‘Page’);?> <input type=’submit’ value='<?php __(“Jump”);?>’ onclick=’jump_to_page(“/brush/comment_tasks/praise_detail/”);’ />
</div>
</div>
<?php echo $this->Html->script(‘jump’); 
require_once(‘webroot/php/action/comment_task.php’);?>


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:cakephp分页功能,paginate联表查询
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址