我在CodeIgniter中有通知系统,当我从Notification类中提取结果时,我创建了一个视图页面,所以我需要帮助,因为我没有任何结果。
这是我的观点 nombre.php:
<?php
if (!isset($_SESSION['id'])) exit;
include ("notif_model.php");
$notification = new notif_model();
$notifications = $notification->getcountNotif();
echo $notifications;
?>
这是我的班级 notif_model.php:
class notif_model extends CI_Model
{
var $type;//reservation request, comment, message
var $to_user;
var $from_user;
var $reference;//comm id, message id
var $timestamp;
var $newcount;
function __construct()
{
parent::__construct();
$this->load->library('session');
}
function insertNotification($notification)
{
$this->db->insert('notification',$notification);
return $this->db->insert_id();
}
function countNotif()
{
$this->db->select('*');
$this->db->where('to_user',$this->session->userdata('id'));
$this->db->where('seen',0);
$query = $this->db->get('notification');
$res = $query->num_rows();
return $res;
}
}
?>
答案 0 :(得分:0)
function countNotif()
{
$this->db->select('*');
$this->db->where('to_user',$this->session->userdata('id'));
$this->db->where('seen',0);
$query = $this->db->get('notification');
$res = $query->num_rows();
echo $this->db->last_query(); exit; // will print the query string
return $res;
}
运行并检查查询....