如何计算codeigniter博客中的帖子视图

I am new in codeigniter and php.

I want to count post view number and store it database.

That means, I want to create a popular post plugin by counting post view.

But i can't do this.

Please anyone help me. Tell the way.

Here is my article Controller..

public function __construct(){
    parent::__construct();
    $this->load->model('article_m');
}

public function index($category_slug, $id, $slug=NULL){

    // Fetch the article
    $this->db->where('pubdate <=', date('Y-m-d'));
    $this->data['article'] = $this->article_m->get($id);
    $this->data['articles'] = $this->article_m->get();


    // Return 404 if not found
    count($this->data['article']) || show_404(uri_string());

    if ($this->uri->segment(1) !== $this->data['cat']->category_slug) {
        echo "Hi There, This is wrong";
    }



    $this->load->view('templates/article', $this->data);
}

}

Here is my Models:

     public function get($id = NULL, $single = FALSE){

    if ($id != NULL) {
        $filter = $this->_primary_filter;
        $id = $filter($id);
        $this->db->where($this->_primary_key, $id);
        $method = 'row';
    }
    elseif($single == TRUE) {
        $method = 'row';
    }
    else {
        $method = 'result';
    }

    if (!count($this->db->ar_orderby)) {
        $this->db->order_by($this->_order_by);
    }
    return $this->db->get($this->_table_name)->$method();
}

Sorry for my bad english..

$post_id = "???"
if(isset($_COOKIE['read_articles'])) {
  //grab the JSON encoded data from the cookie and decode into PHP Array
  $read_articles = json_decode($_COOKIE['read_articles'], true);
   if(isset($read_articles[$post_id]) AND $read_articles[$post_id] == 1) {
     //this post has already been read
   } else {

     //increment the post view count by 1 using update queries

     $read_articles[$post_id] = 1;
     //set the cookie again with the new article ID set to 1
     setcookie("read_articles",json_encode($read_articles),time()+60*60*24);  

   }

} else {

  //hasn't read an article in 24 hours?
  //increment the post view count
  $read_articles = Array(); 
  $read_articles[$post_id] = 1;
  setcookie("read_articles",json_encode($read_articles),time()+60*60*24);      

}

star complex to do?

//function single post, query get by slug and id post


        if(!isset($_SESSION['views'. $id]) || (isset($_SESSION['views'. $id]) && $_SESSION['views'. $id] != $id)){
            $this->post_m->viewer($id); //load model viewer
            $this->session->set_userdata('views'. $id, $id);
        }

// Model "post_m"
function viewer($id)
{
    $this->db->where('id', $id); 
    $this->db->set('views', 'views+1', FALSE);
    $this->db->update('posts'); //table update
} 


$id is id post

</div>