Welcome Guest, Not a member yet? Register   Sign In
DIsplay Category in Post
#2

This may help.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * Class Category_model
 */
class Category_model extends MY_Model
{
    
/**
     * @var  string - Categories table name.
     */
    
private $tableName 'categories';
    
    
/**
     * Category_model constructor.
     * -------------------------------------------------------------------
     *
     */
    
public function __construct()
    {
        
    }

    
// -------------------------------------------------------------------

    /**
     * getCategory ()
     * -------------------------------------------------------------------
     *
     * @param  $id
     * @return array
     */
    
public function getCategory($id)
    {
        
$data    = [];
        
$options = ['id' => $id];

        
$query $this->db->getwhere($this->tableName$options1);

        if (
$query->num_rows() > 0)
        {
            
$data[] = $query->row_array();
        }

        
$query->free_result();

        return 
$data;
    }

    
// -------------------------------------------------------------------

    /**
     * getAllCategories ()
     * -------------------------------------------------------------------
     *
     * @return array
     */
    
public function getAllCategories()
    {
        
$data = [];

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

        if (
$query->num_rows() > 0)
        {
            foreach (
$query->result_array() as $row)
            {
                
$data[] = $row;
            }
        }

        
$query->free_result();

        return 
$data;
    }

    
// -------------------------------------------------------------------

    /**
     * getCategoriesDropDown ()
     * -------------------------------------------------------------------
     *
     * @return array
     */
    
public function getCategoriesDropDown()
    {
        
$data = [];

        
$query $this->db->select('id, title')
         
                 ->get($this->tableName);

        if (
$query->num_rows() > 0)
        {
            foreach (
$query->result_array() as $row)
            {
                
$data[$row['id']] = $row['title'];
            }
        }

        
$query->free_result();

        return 
$data;
    }

    
// -------------------------------------------------------------------

    /**
     * getTopCategories ()
     * -------------------------------------------------------------------
     *
     * @return mixed
     */
    
function getTopCategories()
    {
        
$data = array();

        
$query $this->db->where('parent_id'0)
         
                 ->get($this->tableName);

        if (
$query->num_rows() > 0)
        {
            foreach (
$query->result_array() as $row)
            {
                
$data[$row['id']] = $row['title'];
            }
        }

        
$query->free_result();

        return 
$data;
    }

    
// -------------------------------------------------------------------

    /**
     * addCategory ()
     * -------------------------------------------------------------------
     *
     */
    
function addCategory()
    {
        
$data = [
            
'title'      => str_replace(" ""_"$this->input->post('title'true)),
            
'short_desc' => $this->input->post('short_desc'true),
            
'long_desc'  => $this->input->post('long_desc'true),
            
'status'     => $this->input->post('status'true),
            
'sort_order' => $this->input->post('sort_order'true)
        ];

        
$this->db->insert($this->tableName$data);
    }

    
// -------------------------------------------------------------------

    /**
     * updateCategory ()
     * -------------------------------------------------------------------
     *
     */
    
function updateCategory()
    {
        
$data = [
            
'title'      => str_replace(" ""_"$this->input->post('title'true)),
            
'short_desc' => $this->input->post('short_desc'true),
            
'long_desc'  => $this->input->post('long_desc'true),
            
'status'     => $this->input->post('status'true),
            
'sort_order' => $this->input->post('sort_order'true)
        ];

        
$this->db->where('id'$this->input->post('id'true));
        
$this->db->update($this->tableName$data);

    }

    
// -------------------------------------------------------------------

    /**
     * deleteCategory ()
     * -------------------------------------------------------------------
     *
     * @param $id
     */
    
function deleteCategory($id)
    {
        
$data = ['status' => 'inactive'];

        
$this->db->where('id'$id)
         
        ->update($this->tableName$data);
    }

}

/**
 * -----------------------------------------------------------------------
 * Filename: Category_model.php
 * Location: ./application/models/Category_model.php
 * -----------------------------------------------------------------------
 */ 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
DIsplay Category in Post - by emperaw - 11-17-2018, 11:54 AM
RE: DIsplay Category in Post - by InsiteFX - 11-18-2018, 05:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB