我正在尝试做一些研究,而不是找到我正在寻找的确切内容。我正在使用Codeigniter
和HTML Table Class
,并尝试在$ inbox_messages为空数组的情况下找出我应该在代码中执行的操作。原因是因为我将表格标题和单元格数据放在if语句中的表格中。如果它是一个空数组,我不知道该怎么做,因为在我的视图文件中我告诉它生成表。
// Retrieve all user inbox messages that have not been deleted by the user..
$inbox_messages = array();
// Place to dump the inbox messages object variable to verify it is the expected properties and values for the inbox messages object.
// vardump($inbox_messages);
// Check to see if there are messages returned in the inbox messages object.
if (!empty($inbox_messages))
{
// Add headings to the top of the table for the inbox messages html table.
$this->table->set_heading(form_checkbox(), 'Date Sent', 'Subject', 'From');
// Loop through the inbox messages object and display data for each row.
foreach ($inbox_messages AS $message)
{
$this->table->add_row(form_checkbox(), date('F d, Y', strtotime($message->date_sent)), $message->subject, $message->first_name . ' ' . $message->last_name);
}
}
else
{
// Figure out what to do if object is empty
}
答案 0 :(得分:1)
您可以像@Rajeev Ranjan一样显示no messages
通知,如下面的代码:
if (empty($inbox_messages)) {
$empty_row = array('data' => 'You have no messages', 'colspan' => 4);
$this->table->add_row($empty_row);
} else {
foreach ($inbox_messages AS $message)
{
$this->table->add_row(form_checkbox(), date('F d, Y', strtotime($message->date_sent)), $message->subject, $message->first_name . ' ' . $message->last_name);
}
}