我正在使用数据表来列出我的数据。它以与数据库表中相同的顺序显示我的数据。但我想以不同的顺序展示它。 我的代码:
$userData = array();
$row = array();
$action = array();
foreach ($students as $key => $student) {
foreach ($student as $key => $value) {
switch ($key) {
case 'firstName' :
$firstName = $value;
break;
case 'lastName' :
$lastName = $value;
$row[] = $lastName;
break;
case 'phone' :
$row[] = $value;
break;
case 'email' :
$row[] = $value;
break;
case 'studentId':
$row['DT_RowId'] = $value;
$action[] = "<a id = {$value} class = 'update'>Edit</a>  |  <a id = {$value} class = 'delete'>Delete</a> ";
}
}
$userData[] = array_merge($row, $action);
unset($row);
unset($action);
}
答案 0 :(得分:1)
我没有完全准确,但如果你想要不同顺序的列,我喜欢这样 视图: -
<?php foreach $zendDbRowObject->getTable()->getDisplayOrder() as $fieldName): ?>
<?php echo $zendDbRowObject->$fieldName; ?>
<?php endforeach; ?>
controllar: -
public function getDisplayOrder() {
// fake column names obviously... use yours here.
return array(
'column5',
'column1',
'column4',
'column2',
'column3'
);
}