Yehonatan

model.php

Jul 31st, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.21 KB | None | 0 0
  1. <?php
  2.     //require_once dirname(dirname(__FILE__)) . "/config/config.php";
  3.     class model extends  Loader
  4.     {
  5.        
  6.         private $models;
  7.        
  8.         function __construct()
  9.         {
  10.             parent::__construct();
  11.         }
  12.        
  13.         public function load_model($model_name,$data = array())
  14.         {
  15.             if($model_name != 'model')
  16.             {
  17.                 if(file_exists(dirname(__FILE__) . "/" . $model_name . ".php"))
  18.                 {
  19.                     if(in_array($model_name, get_declared_classes()))
  20.                         $this->logger->output('Class ' . $model_name . ' is already declared.','error');
  21.                     else {
  22.                             require_once(dirname(__FILE__) . "/" . $model_name . ".php");
  23.                             $this->models[$model_name] = new $model_name($data);
  24.                             return true;
  25.                     }
  26.                 }
  27.                 else {
  28.                         $this->logger->output('File ' . $model_name . '.php dose not exists.','error');
  29.                         return false;
  30.                 }
  31.             }
  32.             else {
  33.                     $this->logger->output('Model name can\'t be "model"','error');
  34.                     return false;
  35.             }  
  36.         }
  37.        
  38.         public function get_model($model_name)
  39.         {
  40.             if(array_key_exists($model_name, $this->models))
  41.                 return $this->models[$model_name];
  42.             else {
  43.                     $this->logger->output('Model name could not be found. Model ' . $model_name,'error');
  44.                     return false;
  45.             }
  46.         }
  47.     }
  48.    
  49.    
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment