我正在使用CakePHP 3,并且我正在尝试为相关数据创建分页,换句话说,所有记录都属于第一个表格。我怎么能在cakephp中创建相关数据的分页3
例
我有两个表
用户
User_Profiles
用户的hasMany配置文件,所以当我上的任何用户点击它会显示我与V相关的个人资料浏览功能,
想象一下,如果我对该特定用户有10000个配置文件,将很难显示所有1000个配置文件,我如何为他们分页?
这是我的控制器
public function view($id = null)
{
$distributor = $this->Distributors->get($id, [
'contain' => ['DistributorUsers', 'Participants', 'Payments']
]);
$this->set('distributor', $distributor);
$this->set('_serialize', ['distributor']);
}
从功能,我们可以看到我们有,如果我对每个表10000记录也将可以在视图模板而不分页3个表是相关的,这是真的很难加载页面,甚至阅读所有,
这是我的看法
<table class="table table-condensed table-hover">
<thead>
<tr>
<th colspan="3"> <?= h($distributor->name) ?> </th>
</tr>
</thead>
<tbody>
<tr>
<td><?= __('Name') ?></th>
<td><?= h($distributor->name) ?></td>
</tr>
<tr>
<td><?= __('Location') ?></th>
<td><?= h($distributor->location) ?></td>
</tr>
<tr>
<td><?= __('Phone') ?></th>
<td><?= h($distributor->phone) ?></td>
</tr>
<tr>
<td><?= __('Id') ?></th>
<td><?= $this->Number->format($distributor->id) ?></td>
</tr>
<tr>
<td><?= __('Created') ?></th>
<td><?= h($distributor->created) ?></td>
</tr>
<tr>
<td><?= __('Active') ?></th>
<td><?= $distributor->active ? __('Yes') : __('No'); ?></td>
</tr>
</table>
<div class="related">
<h4><?= __('Related Distributor Users') ?></h4>
<?php if (!empty($distributor->distributor_users)): ?>
<table class="table table-hover" id="sample-table-1">
<thead>
<tr>
<th><?= __('Id') ?></th>
<th><?= __('Level') ?></th>
<th><?= __('Username') ?></th>
<th><?= __('Email') ?></th>
<th><?= __('Created') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($distributor->distributor_users as $distributorUsers): ?>
<tr>
<td><?= h($distributorUsers->id) ?></td>
<td><?= h($distributorUsers->level) ?></td>
<td><?= h($distributorUsers->username) ?></td>
<td><?= h($distributorUsers->email) ?></td>
<td><?= h($distributorUsers->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'DistributorUsers', 'action' => 'view', $distributorUsers->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'DistributorUsers', 'action' => 'edit', $distributorUsers->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'DistributorUsers', 'action' => 'delete', $distributorUsers->id], ['confirm' => __('Are you sure you want to delete # {0}?', $distributorUsers->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="related">
<h4><?= __('Related Participants') ?></h4>
<?php if (!empty($distributor->participants)): ?>
<table class="table table-hover" id="sample-table-1">
<thead>
<tr>
<th><?= __('Id') ?></th>
<th><?= __('Age') ?></th>
<th><?= __('Dateofbirth') ?></th>
<th><?= __('Gender') ?></th>
<th><?= __('Address') ?></th>
<th><?= __('Mobile') ?></th>
<th><?= __('Relatives Phone') ?></th>
<th><?= __('Has Disease') ?></th>
<th><?= __('Disease') ?></th>
<th><?= __('Ip Address') ?></th>
<th><?= __('Distributor Id') ?></th>
<th><?= __('Event Id') ?></th>
<th><?= __('Is First Time') ?></th>
<th><?= __('Is Payment Done') ?></th>
<th><?= __('Confirm Attendance') ?></th>
<th><?= __('First Name') ?></th>
<th><?= __('Second Name') ?></th>
<th><?= __('Third Name') ?></th>
<th><?= __('Last Name') ?></th>
<th><?= __('Lockbox Number') ?></th>
<th><?= __('Created') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($distributor->participants as $participants): ?>
<tr>
<td><?= h($participants->id) ?></td>
<td><?= h($participants->age) ?></td>
<td><?= h($participants->dateofbirth) ?></td>
<td><?= h($participants->gender) ?></td>
<td><?= h($participants->address) ?></td>
<td><?= h($participants->mobile) ?></td>
<td><?= h($participants->relatives_phone) ?></td>
<td><?= h($participants->has_disease) ?></td>
<td><?= h($participants->disease) ?></td>
<td><?= h($participants->ip_address) ?></td>
<td><?= h($participants->distributor_id) ?></td>
<td><?= h($participants->event_id) ?></td>
<td><?= h($participants->is_first_time) ?></td>
<td><?= h($participants->is_payment_done) ?></td>
<td><?= h($participants->confirm_attendance) ?></td>
<td><?= h($participants->first_name) ?></td>
<td><?= h($participants->second_name) ?></td>
<td><?= h($participants->third_name) ?></td>
<td><?= h($participants->last_name) ?></td>
<td><?= h($participants->lockbox_number) ?></td>
<td><?= h($participants->created) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'Participants', 'action' => 'view', $participants->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'Participants', 'action' => 'edit', $participants->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'Participants', 'action' => 'delete', $participants->id], ['confirm' => __('Are you sure you want to delete # {0}?', $participants->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<div class="related">
<h4><?= __('Related Payments') ?></h4>
<?php if (!empty($distributor->payments)): ?>
<table class="table table-hover" id="sample-table-1">
<thead>
<tr>
<th><?= __('Id') ?></th>
<th><?= __('Participant Id') ?></th>
<th><?= __('Distributor Id') ?></th>
<th><?= __('Event Id') ?></th>
<th><?= __('Distributor User Id') ?></th>
<th><?= __('Amount') ?></th>
<th><?= __('Created') ?></th>
<th><?= __('Ip Address') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($distributor->payments as $payments): ?>
<tr>
<td><?= h($payments->id) ?></td>
<td><?= h($payments->participant_id) ?></td>
<td><?= h($payments->distributor_id) ?></td>
<td><?= h($payments->event_id) ?></td>
<td><?= h($payments->distributor_user_id) ?></td>
<td><?= h($payments->amount) ?></td>
<td><?= h($payments->created) ?></td>
<td><?= h($payments->ip_address) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'Payments', 'action' => 'view', $payments->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'Payments', 'action' => 'edit', $payments->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'Payments', 'action' => 'delete', $payments->id], ['confirm' => __('Are you sure you want to delete # {0}?', $payments->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div></div>
请帮帮忙,谢谢
'我有两个tables'你的代码使用了完全不同的名字 - 请desribe你的实际问题,而不是它的简单化版本 - 即作出描述一致与问题中的代码。 – AD7six