Exemple #1
0
 public static function __callStatic($method, $args)
 {
     $db = Inflector::uncamelize($method);
     if (fnmatch('*_*', $db)) {
         list($database, $table) = explode('_', $db, 2);
     } else {
         $database = SITE_NAME;
         $table = $db;
     }
     if (empty($args)) {
         return Db::instance($database, $table);
     } elseif (count($args) == 1) {
         $id = Arrays::first($args);
         if (is_numeric($id)) {
             return Db::instance($database, $table)->find($id);
         }
     }
 }
Exemple #2
0
 public function fieldsRow()
 {
     $first = Db::instance($this->db, $this->table)->first(true);
     if ($first) {
         $fields = array_keys($first->assoc());
         unset($fields['id']);
         unset($fields['created_at']);
         unset($fields['updated_at']);
         unset($fields['deleted_at']);
         return $fields;
     } else {
         return [];
     }
 }
Exemple #3
0
 public function __construct($ns)
 {
     $this->ns = $ns;
     $this->db = Db::instance('core', 'log');
 }
Exemple #4
0
 public function pivot($model)
 {
     if ($model instanceof Db) {
         $model = $model->model();
     }
     $mTable = $model->db()->table;
     $names = [$this->_db->table, $mTable];
     asort($names);
     $pivot = Inflector::lower('pivot' . implode('', $names));
     return Db::instance($this->_db->db, $pivot);
 }