douyan5481 2016-12-18 18:27
浏览 34
已采纳

在自己的表中为多个集使用相同的模板

I'm doing some experimenting with CakePHP and I came across the following:

Take users, each user is in a specific state (f.e. inactive, banned, new, ...). Each user has only one of these states.

Now apart from this state all users are part of the same Model (Users). So their visual representation in a template with a html table is exactly the same.

What I want to do now is putting all the users in the same state in the same table. Having a different table for each state.

It looks silly to go around and repeating the same template code for each set of users.

What's the proper way to handle this in CakePHP 3?

  • 写回答

1条回答 默认 最新

  • dtsc1684 2016-12-19 01:24
    关注

    If you really want a different table for each set, then an element might be the way to do. Or simply wrap the entire table in a foreach ($states as $state) in your view. Either are easily done.

    But I'd suggest that perhaps what you want is really to put them all in one table with subheadings? That way, the columns will all be the same width for each state. To do that, I'd have all the users in a single query result, ordered by state (and then name, or whatever is helpful), and then as you loop through them, you check to see whether the state is different than it was for the last user, and if so output an extra line with <th colspan="x"><?= $user->state ?></th> or some such.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作