使用JQuery进行Codeigniter未读通知计数

时间:2017-10-22 14:02:32

标签: php jquery mysql codeigniter

CLICK TO VIEW MY EXAMPLE NOTIFICATION

有谁知道如何在codeigniter中显示和更新通知计数?我尝试了很多方法,但仍然没有运气。顺便说一下,我还没有尝试过Jquery。你能帮我看看如何使用MVC模式用JQuery编写代码吗?

视图:header.php

<li class="green dropdown-modal">
                        <a data-toggle="dropdown" class="dropdown-toggle" href="<?php echo base_url();?>admin/notification/read_notifications">
                            <i class="ace-icon fa fa-bell icon-animated-bell"></i>
                            <span class="badge badge-success">2</span>
                        </a>
                        <ul class="green dropdown-menu-right dropdown-navbar dropdown-menu dropdown-caret dropdown-close">

                            <li class="dropdown-header">
                                <i class="ace-icon fa fa-exclamation-triangle"></i>
                                2 Notifications
                            </li>

                            <li class="dropdown-content">
                                <ul class="dropdown-menu dropdown-navbar">
                                    <?php foreach($notification as $notif):?>
                                    <li>
                                        <a href="" class="clearfix">
                                            <img src="<?php echo base_url();?>avatars/<?php echo $user->avatar;?>" class="msg-photo" alt="Alex's Avatar" />
                                            <span class="msg-body">
                                                <span class="msg-title">
                                                    <?php echo $notif->message;?>
                                                </span>

                                                <span class="msg-time">
                                                    <i class="ace-icon fa fa-clock-o"></i>
                                                    <span><?php echo date(" M j, Y, g:i A",strtotime($notif->date));?></span>
                                                </span>
                                            </span>
                                        </a>
                                    </li>
                                    <?php endforeach;?>

                                </ul>
                            </li>


                            <li class="dropdown-footer">
                                <a href="#">
                                    See all notifications
                                    <i class="ace-icon fa fa-arrow-right"></i>
                                </a>
                            </li>
                        </ul>
                    </li>

CONTROLLER:Notification.php (当用户点击通知按钮时)

<?php
class Notification extends MY_Controller{
    public function __construct(){
        parent:: __construct();
        if(!$this->session->userdata('loggedin')){
            redirect("login");
        }
        else{
            $this->get_usersession();
        }
    }
   public function read_notifications(){
        $data=array(
            'isread' =>'1'
        );
        $this->db->update('tblnotification',$data);

    }

}

&GT;

** MODEL:Notification.php **(这将获得管理员的所有通知)

public function get_admin_notification(){
        $this->db->select('a.*, b.title AS title, b.file as file, CONCAT(c.firstname," ",c.lastname) AS contributor, c.avatar as avatar');
        $this->db->from('tblnotification as a');
        $this->db->where('adminid = 0');
        $this->db->join('tblarticles as b','b.articleid = a.articleid','left');
        $this->db->join('tblusers as c','c.id=a.userid','left');
        $this->db->order_by('date','DESC');

        $query=$this->db->get();

        return $query->result();

    }

CONTROLLER:MY_Controller.php (这是我获取通知的地方)

<?php
//Glbal Controller
class MY_Controller extends CI_Controller{

    public function get_usersession(){

        $session_data = $this->session->userdata('username');

        $data['user']=$this->Authenticate_model->get_login($session_data);
        $data['notification'] = $this->Notification_model->get_admin_notification();

        $admin = $this->Authenticate_model->get_login($session_data);

        if(!($admin->groupname == "Administrator")){

            redirect(base_url());       
        }else{

            $this->load->view('admin/layouts/includes/header',$data);
        }

    }
    public function get_usersession_dashboard(){

        if(!$this->session->userdata('loggedin')){

            $data['user']="";

            $this->load->view('layoutsdashboard/header',$data);


        }else{

            $session_data = $this->session->userdata('username');

            $data['user']=$this->Authenticate_model->get_login($session_data);

            $this->load->view('layoutsdashboard/header',$data);
        }


    }




}

&GT;

enter image description here

0 个答案:

没有答案