0

我正在尝试做一些研究,但没有找到我正在寻找的东西。我正在使用CodeigniterandHTML 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                 
}
4

1 回答 1

1

您可以no messages像@Rajeev Ranjan 所说的那样显示通知,如下代码:

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);
    }
}
于 2013-08-22T09:02:38.637 回答