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.

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

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM