Bootstrap 通知警报
Bootstrap Notification Alerts
我有一个 Codeigniter 项目来管理信件的详细信息。然后我需要在菜单栏中通知没有紧急信件作为 Bootstrap 通知给每个主题用户。紧急信件在分类栏中用 2(二)表示。
控制器
public function index()
{
$meta=array(
'UrgentLetters'=>$this->Welcome_Model->getUrgentLetters()
);
$this->load->view('header',$meta);
$this->load->view('dashboard');
$this->load->view('footer');
}
型号
function getUrgentLetters()
{
$subject = $this->session->userdata('subject_id');
$this->db->select("letter_subject.subject_name AS subjects, count(letter_id) AS no_of_urgent");
$this->db->from('letter_letter');
$this->db->join('letter_subject', 'letter_subject.subject_id=letter_letter.subject');
$this->db->where('letter_letter.status=1 and letter_letter.classification=2');
$this->db->group_by('subject_name');
if ($subject && $subject !=100)
$this->db->where('letter_letter.subject', $subject);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q;
}
}
查看
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-info"><?= count($UrgentLetters) ?></span>
</a>
<ul class="dropdown-menu" style="width: 940px">
<li class="header">You have <?= count($UrgentLetters)?> Urgent Letters</li>
<li>
<!-- Inner Menu: contains the notifications -->
<ul class="menu">
<table style="width: 100%">
<thead style="padding-bottom: 10px">
<tr style="width: 100%">
<th style="width: 40%;padding-left: 2%;padding-bottom: 5px;padding-top: 5px">Subject Name</th>
<th style="width: 40%;padding-bottom: 5px;padding-top: 5px">Letter Count</th>
</tr>
</thead>
<tbody>
<?php foreach ($UrgentLetters as $UrgentLetterss){
$subjects=$UrgentLetterss->subjects;
$no_of_urgent = $UrgentLetterss->no_of_urgent;
echo "<tr>";
echo "<td style='width: 45%;padding-left: 2%'>$subjects</td>";
echo "<td style='width: 45%'>$no_of_urgent->desc</td>";
echo "</tr>";
}?>
</tbody>
</table>
</ul>
</li>
</ul>
</li>
所有部分都工作正常。但是遇到如下错误。
A PHP Error was encountered
Severity: Notice
Message: Undefined property: PDO::$subjects
Filename: views/header.php
Line Number: 111
可能是什么原因?有人可以帮忙吗?
您缺少 return 类似
的查询结果
if ($q->num_rows() > 0) {
return $q->result();
}
现在您只需发送一个 CI_DB_mysqli_result 对象,因此您会在视图中收到错误消息。
我有一个 Codeigniter 项目来管理信件的详细信息。然后我需要在菜单栏中通知没有紧急信件作为 Bootstrap 通知给每个主题用户。紧急信件在分类栏中用 2(二)表示。
控制器
public function index()
{
$meta=array(
'UrgentLetters'=>$this->Welcome_Model->getUrgentLetters()
);
$this->load->view('header',$meta);
$this->load->view('dashboard');
$this->load->view('footer');
}
型号
function getUrgentLetters()
{
$subject = $this->session->userdata('subject_id');
$this->db->select("letter_subject.subject_name AS subjects, count(letter_id) AS no_of_urgent");
$this->db->from('letter_letter');
$this->db->join('letter_subject', 'letter_subject.subject_id=letter_letter.subject');
$this->db->where('letter_letter.status=1 and letter_letter.classification=2');
$this->db->group_by('subject_name');
if ($subject && $subject !=100)
$this->db->where('letter_letter.subject', $subject);
$q = $this->db->get();
if ($q->num_rows() > 0) {
return $q;
}
}
查看
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-bell-o"></i>
<span class="label label-info"><?= count($UrgentLetters) ?></span>
</a>
<ul class="dropdown-menu" style="width: 940px">
<li class="header">You have <?= count($UrgentLetters)?> Urgent Letters</li>
<li>
<!-- Inner Menu: contains the notifications -->
<ul class="menu">
<table style="width: 100%">
<thead style="padding-bottom: 10px">
<tr style="width: 100%">
<th style="width: 40%;padding-left: 2%;padding-bottom: 5px;padding-top: 5px">Subject Name</th>
<th style="width: 40%;padding-bottom: 5px;padding-top: 5px">Letter Count</th>
</tr>
</thead>
<tbody>
<?php foreach ($UrgentLetters as $UrgentLetterss){
$subjects=$UrgentLetterss->subjects;
$no_of_urgent = $UrgentLetterss->no_of_urgent;
echo "<tr>";
echo "<td style='width: 45%;padding-left: 2%'>$subjects</td>";
echo "<td style='width: 45%'>$no_of_urgent->desc</td>";
echo "</tr>";
}?>
</tbody>
</table>
</ul>
</li>
</ul>
</li>
所有部分都工作正常。但是遇到如下错误。
A PHP Error was encountered
Severity: Notice
Message: Undefined property: PDO::$subjects
Filename: views/header.php
Line Number: 111
可能是什么原因?有人可以帮忙吗?
您缺少 return 类似
的查询结果if ($q->num_rows() > 0) {
return $q->result();
}
现在您只需发送一个 CI_DB_mysqli_result 对象,因此您会在视图中收到错误消息。