Это вспомогательная функция, которую я написал, чтобы сделать именно это:
function auto_table($cells, $cols, $class = '') {
$table = '<table' . (empty($class) ? '' : ' class="' . $class . '"') .'><tbody><tr>';
$current_col = 1;
foreach ($cells as $cell) {
// Add the cell
$table .= "<td class=\"col-$current_col\">$cell</td>";
if ($current_col % $cols == 0) {
$table .= '</tr><tr>';
$current_col = 1;
}
else {
$current_col++;
}
}
// Clear up
$remaining = $cols - ($current_col == 1 ? 4 : ($current_col - 1));
for ($i = 0; $i < $remaining; $i++) {
$table .= '<td class="col-' . $current_col++ . '"> </td>';
}
$table .= '</tr></tbody></table>';
return $table;
}
$cells
будет содержать массив данных, $cols
количество столбцов для таблицы и $class
любой класс, добавляемый в таблицу.
UPDATE
Интегрировано с вашим кодом:
$cells = array();
foreach ($professionalPassion as $us) {
$cell = 'Type: ' . $us['PassionsUser']['type'] . '<br />';
$cell .= 'Description: ' . $us['PassionsUser']['description'] . '<br />';
$cell .= $this->Html->link(__('Edit', true), array('controller' => 'PassionsUsers', 'action' => 'edit_passion', $us['PassionsUser']['id']));
$cell .= ' | ';
$cell .= $this->Html->link(__('Delete', true), array('controller' => 'PassionsUsers', 'action' => 'delete', $us['PassionsUser']['id']));
$cells[] = $cell;
}
$html_table = auto_table($cells, 3);