<?php
class model
{
private $__instance; # class instance
protected $__file_name; # model file
protected $db; # global db object
function __construct($db, $name)
{
$this->db = $db;
$this->__file_name = $name;
}
# runs the specified model function
public function run($name)
{
#model file path
$path = __SITE_PATH . '/models' . '/' . $this->__file_name . 'Model.php';
if (file_exists($path) == false)
{
throw new Exception('Model not found in '. $path);
return false;
}
require_once ($path);
# instansiate the model class and get the value
$__class = $this->__file_name . 'Model';
$this->__instance = new $__class($this->db, $this->__file_name);
$__value = $this->__instance->$name();
return $__value;
}
}
?>