// ./application/core/MY_Model.php
class MY_Model extends CI_Model
{
/**
* --------------------------------------------------------------------
* Class variables - public, private, protected and static.
* --------------------------------------------------------------------
*/
public $tableName; // Holds the database table name.
public $limit = 20; // Default database record limit.
// --------------------------------------------------------------------
/**
* __Construct()
*
* Constructor PHP 5+ NOTE: Not needed if not setting values!
*
*/
public function __construct()
{
parent::__construct();
}
/**
* -----------------------------------------------------------------------
* Return Object's:
* result() = $row->title;
* row() = $row->title;
*
* Return Array's:
* result_array() = $row['title'];
* row_array() = $row['title'];
* -----------------------------------------------------------------------
*/
// -----------------------------------------------------------------------
/**
* setTableName()
*
* @param string $tableName
*/
public function setTableName($tableName = '')
{
$this->tableName = $tableName;
}
}
// ./application/models/Your_model.php
class Your_model extends MY_Model
{
/**
* Class properties - public, private, protected and static.
* -----------------------------------------------------------------------
*/
/**
* __construct ()
* -----------------------------------------------------------------------
*
* Class Constructor
*
* NOTE: Not needed if not setting values or extending a Class.
*/
public function __construct()
{
parent::__construct();
$this->setTableName('tableName');
log_message('debug', "Name Model Class Initialized");
}
/**
* getPost ()
* -------------------------------------------------------------------
*
* EXAMPLE:
*
* @param string $id
* @return array
*/
public function getPost($id = '')
{
$data = array();
$this->db->where('id', $id);
$this->db->limit(1);
$query = $this->db->get($this->tableName);
if ($query->num_rows() > 0)
{
$data = $query->row_array();
}
$query->free_result();
return $data;
}
}