Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. defined('BASEPATH') OR exit('No direct script access allowed');
  4.  
  5. class Blog_m extends CI_Model{
  6.  
  7.     public function getBlog(){
  8.         $this->db->order_by('created_at', 'desc');
  9.         $query = $this->db->get('tbl_blogs');
  10.         if($query->num_rows() > 0){
  11.             return $query->result();
  12.         }else{
  13.             return false;
  14.         }
  15.     }
  16.  
  17.     public function submit(){
  18.         $field = array(
  19.             'title'=>$this->input->post('txt_title'),
  20.             'description'=>$this->input->post('txt_description'),
  21.             'created_at'=>date('Y-m-d H:i:s')
  22.             );
  23.         $this->db->insert('tbl_blogs', $field);
  24.         if($this->db->affected_rows() > 0){
  25.             return true;
  26.         }else{
  27.             return false;
  28.         }
  29.     }
  30.  
  31.     public function getBlogById($id){
  32.         $this->db->where('id', $id);
  33.         $query = $this->db->get('tbl_blogs');
  34.         if($query->num_rows() > 0){
  35.             return $query->row();
  36.         }else{
  37.             return false;
  38.         }
  39.     }
  40.  
  41.     public function update(){
  42.         $id = $this->input->post('txt_hidden');
  43.         $field = array(
  44.             'title'=>$this->input->post('txt_title'),
  45.             'description'=>$this->input->post('txt_description'),
  46.             'updated_at'=>date('Y-m-d H:i:s')
  47.             );
  48.         $this->db->where('id', $id);
  49.         $this->db->update('tbl_blogs', $field);
  50.         echo $this->db->last_query();extit;
  51.         if($this->db->affected_rows() > 0){
  52.             return true;
  53.         }else{
  54.             return false;
  55.         }
  56.     }
  57.  
  58.     public function delete($id){
  59.         $this->db->where('id', $id);
  60.         $this->db->delete('tbl_blogs');
  61.         if($this->db->affected_rows() > 0){
  62.             return true;
  63.         }else{
  64.             return false;
  65.         }
  66.     }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement