예제 #1
0
파일: Model.php 프로젝트: jesgs/greenmvc
 /**
  * PHP5 Constructor method
  */
 public function __construct($values = array())
 {
     $this->db = Db::getInstance();
     // if either rowClass or $values are empty, then we just want
     // an empty model. Return out, nothing else to do.
     if (!$this->rowClass || empty($values)) {
         return;
     }
     try {
         $tableDataColumns = $this->db->query("DESCRIBE {$this->table}");
         if (!$tableDataColumns) {
             throw new \Exception("Table not defined or found.");
         }
     } catch (\Exception $e) {
         die($e->getMessage());
     }
     $this->tableData = $tableDataColumns;
     $this->row = new $this->rowClass();
     foreach ($tableDataColumns as $column) {
         $field = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $column['Field']))));
         if (!property_exists($this->row, $field)) {
             $this->{$field} = null;
         }
     }
     foreach ($values as $property => $value) {
         $method = "set{$property}";
         if (method_exists($this->row, $method)) {
             $this->row->{$method}($value);
         }
     }
 }
예제 #2
0
파일: load.php 프로젝트: jesgs/greenmvc
/**
 * Do things to close down the app on shutdown
 */
function shutdown()
{
    $db = \GreenMvc\Db\Db::getInstance();
    $db->close();
    if (DEBUG && IS_CLI) {
        echo "kthnxbye" . PHP_EOL;
    }
}