CakePHP - 使用 group by 打印单个表头
我有一个模型任务列表,每个任务列表项都属于一个服务项。
在我的任务列表控制器中:
function index() {
$this->Tasklist->recursive = 0;
$this->set('tasklists', $this->Tasklist->find('all', array(
'order' => array(
'Service.name' => 'ASC',
'Tasklist.name' => 'ASC'
)
)));
}
我的简单索引视图的相关部分:
<?php foreach ($tasklists as $tasklist): ?>
<tr>
<td><?php echo $tasklist['Tasklist']['id']; ?></td>
<td><?php echo $tasklist['Tasklist']['name']; ?></td>
<td>
<?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?>
</td>
<td><?php echo $tasklist['Tasklist']['created']; ?></td>
<td><?php echo $tasklist['Tasklist']['modified']; ?></td>
<td>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
</td>
</tr>
<?php endforeach; ?>
我不想在每个表行中打印服务名称,而是将其打印为将任务列表分组在每个列表下:
<tr>
<th colspan="5"><?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?></th>
</tr>
<tr>
<td><?php echo $tasklist['Tasklist']['id']; ?></td>
<td><?php echo $tasklist['Tasklist']['name']; ?></td>
<td><?php echo $tasklist['Tasklist']['created']; ?></td>
<td><?php echo $tasklist['Tasklist']['modified']; ?></td>
<td>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
</td>
</tr>
我已经尝试在控制器中使用组参数在我看来,还有一个嵌套的 foreach,但无法让它工作。
I have a model Tasklist, and each Tasklist item belongs to a Service item.
In my Tasklist controller:
function index() {
$this->Tasklist->recursive = 0;
$this->set('tasklists', $this->Tasklist->find('all', array(
'order' => array(
'Service.name' => 'ASC',
'Tasklist.name' => 'ASC'
)
)));
}
Relevant part of my simple index View:
<?php foreach ($tasklists as $tasklist): ?>
<tr>
<td><?php echo $tasklist['Tasklist']['id']; ?></td>
<td><?php echo $tasklist['Tasklist']['name']; ?></td>
<td>
<?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?>
</td>
<td><?php echo $tasklist['Tasklist']['created']; ?></td>
<td><?php echo $tasklist['Tasklist']['modified']; ?></td>
<td>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
</td>
</tr>
<?php endforeach; ?>
Instead of printing the Service name in every table row I would like to print it as a with the Tasklists grouped beneath each one:
<tr>
<th colspan="5"><?php echo $this->Html->link($tasklist['Service']['name'], array('controller' => 'services', 'action' => 'view', $tasklist['Service']['id'])); ?></th>
</tr>
<tr>
<td><?php echo $tasklist['Tasklist']['id']; ?></td>
<td><?php echo $tasklist['Tasklist']['name']; ?></td>
<td><?php echo $tasklist['Tasklist']['created']; ?></td>
<td><?php echo $tasklist['Tasklist']['modified']; ?></td>
<td>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $tasklist['Tasklist']['id']), array('class' => 'button edit')); ?>
</td>
</tr>
I have experimented with using the group parameter in my controller and a nested foreach in my view, but cannot get it to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会这样做
I'd do it like this