예제 #1
0
파일: Model.php 프로젝트: rickb838/scalr
 public function __call($name, $arguments)
 {
     if (!strncmp($name, "loadBy", 6) && count($arguments) > 0) {
         $name = lcfirst(substr($name, 6));
         $property = $this->findDbKeyByProperty($name);
         $value = $arguments[0];
         $loadFlag = !isset($arguments[1]) || isset($arguments[1]) && $arguments[1];
         if ($property && is_array($this->dbPropertyMap[$property]) && isset($this->dbPropertyMap[$property]['is_filter']) && $this->dbPropertyMap[$property]['is_filter']) {
             if ($loadFlag) {
                 $info = $this->db->getRow("SELECT * FROM {$this->dbTableName} WHERE {$property} = ? LIMIT 1", array($value));
                 if (!$info) {
                     throw new Exception(sprintf(_($this->dbMessageKeyNotFound), $value));
                 }
                 return $this->loadBy($info);
             } else {
                 return $this->db->getAll("SELECT * FROM {$this->dbTableName} WHERE {$property} = ?", array($value));
             }
         }
     }
     throw new Exception(_("Method '{$name}' of class '" . get_called_class() . "' not found"));
 }