Esempio n. 1
0
 /**
  *  constructor
  *  @param  mixed   param   PDO instance,
  *                          or record id (if integer),
  *                          or constraints (if array) but param['pdo'] is PDO instance
  */
 function __construct($params = null)
 {
     try {
         if (!self::$db && self::$adapter) {
             self::$db = new self::$adapter(self::$db_settings);
         }
     } catch (Exception $e) {
         throw new WaxDbException("Cannot Initialise DB", "Database Configuration Error");
     }
     $class_name = get_class($this);
     if ($class_name != 'WaxModel' && !$this->table) {
         $this->table = Inflections::underscore($class_name);
     }
     if ($params && is_numeric($params)) {
         $res = $this->filter(array($this->primary_key => $params))->first();
         $this->row = $res->row;
         $this->clear();
     }
     $this->define($this->primary_key, $this->primary_type, $this->primary_options);
     $this->setup();
     $this->set_identifier();
     // If a scope is passed into the constructor run a method called scope_[scope]().
     if ($params && is_string($params)) {
         $method = "scope_" . $params;
         if (method_exists($this, $method)) {
             $this->{$method};
         }
     }
 }