DIsplay Category in Post - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: DIsplay Category in Post (/showthread.php?tid=72193) |
DIsplay Category in Post - emperaw - 11-17-2018 Hello, I'm new to codeigniter, am creating a small website that as a blog with 1 to many relationship, with the help of tutorial on creating MY_Model, of which i did, and now i want to display category to each post. this is my post_m.php <?php class Post_m extends MY_Model { protected $_table_name = 'posts'; protected $_order_by = 'pubdate desc, id desc'; protected $_timestamps = TRUE; public $rules = array( 'pubdate' => array( 'field' => 'pubdate', 'label' => 'Publication date', 'rules' => 'trim|required|exact_length[10]' ), 'title' => array( 'field' => 'title', 'label' => 'Title', 'rules' => 'trim|required|max_length[100]' ), 'slug' => array( 'field' => 'slug', 'label' => 'Slug', 'rules' => 'trim|required|max_length[100]|url_title' ), 'body' => array( 'field' => 'body', 'label' => 'Body', 'rules' => 'trim|required' ) ); public function get_new () { $post = new stdClass(); $post->title = ''; $post->slug = ''; $post->body = ''; $post->name = ''; $post->post_image = ''; $post->pubdate = date('Y-m-d'); return $post; } public function set_published(){ $this->db->where('pubdate <=', date('Y-m-d')); } public function get_recent($limit = 3){ // Fetch a limited number of recent articles $limit = (int) $limit; $this->set_published(); $this->db->limit($limit); return parent::get(); } public function get_categories() { $this->db->order_by('name'); $query = $this->db->get('categories'); return $query->result_array(); } } RE: DIsplay Category in Post - InsiteFX - 11-18-2018 This may help. PHP Code: <?php |