在自己的表中为多个集使用相同的模板
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?
我正在尝试使用CakePHP,我遇到了以下情况: p> 吸引用户,每个用户都处于特定状态(非活动,禁用,新建,......)。 每个用户只有其中一种状态。 p>
现在除了这种状态外,所有用户都属于同一个模型(用户)。 因此,他们在带有html表的模板中的可视化表示是 完全相同。 p>
我现在要做的是将所有用户置于同一个表中的同一状态。 每个州都有一个不同的表。 p>
为每组用户重复相同的模板代码看起来很愚蠢。 p>
什么是 在CakePHP 3中处理此问题的正确方法是什么? p> div>
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.