Codeigniter_Blog_App/application/models/Category_model.php

39 lines
866 B
PHP
Raw Normal View History

2024-07-11 04:23:32 +00:00
<?php
class Category_model extends CI_Model {
public function __construct(){
$this->load->database();
}
public function get_categories(){
$this->db->order_by('name');
$query = $this->db->get('categories');
return $query->result_array();
}
public function create_category(){
$data = array(
'name' => $this->input->post('name'),
'user_id' => $this->session->userdata('user_id')
);
return $this->db->insert('categories', $data);
}
public function get_category($category_id){
$query = $this->db->get_where('categories',array('id' => $category_id));
return $query->row();
}
public function delete_category($id){
$this->db->where('id', $id);
$this->db->delete('categories');
return true;
}
}