使用HtmlHelper
构建表格时,有没有办法在所有<tr>
行中添加ID等属性?
e.g。这是我当前<tbody>
代码的简化版本:
foreach ($subjects as $subject) {
echo $this->Html->tableCells(
array(
$subject['Subject']['id'],
$subject['Subject']['name']
),
array('class' => 'odd'), null, true
);
}
我希望表格能像:
<tr id="subj-34"><td ...
<tr id="subj-263"><td ...
<tr id="subj-11"><td ...
答案 0 :(得分:2)
我意识到这是一个比我想象的更简单的案例。您只需将id属性添加到第二个和第三个参数(以便它适用于偶数行和奇数行)。
foreach ($subjects as $subject) {
echo $this->Html->tableCells(
array(
$subject['Subject']['id'],
$subject['Subject']['name']
),
array('class' => 'odd', 'id' = > 'subj-'.$subject['Subject']['id']),
array('id' = > 'subj-'.$subject['Subject']['id']),
true
);
}