示例#1
0
文件: crud.php 项目: nemis/Fm
 public static function table($modelName, &$db, $columns = false)
 {
     self::checkSave($modelName, $db);
     self::checkDelete($modelName, $db);
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $orderby = isset($_GET['orderby']) ? $_GET['orderby'] : 'id';
     $model = $db->model($modelName);
     $iterations = $model->orderby($orderby)->limit(self::$perPage, ($page - 1) * self::$perPage)->findAll();
     if (isset($_GET['search']) and is_arary($_GET['search'])) {
         foreach ($_GET['search'] as $k => $v) {
             $model->like($k, $v);
         }
     }
     $tableView = new View('crud_table');
     $tableView->iterations = $iterations;
     $tableView->columns = $columns ? $columns : $model->fields();
     $tableView->page = $page;
     $tableView->pagination = Pagination::links($page, $tableView->countAll = $model->countAll(), self::$perPage);
     return $tableView->render();
 }
示例#2
0
 public final function table_fields(&$fields = null, $tablename = null, $tables = null)
 {
     $this->connect();
     if (null === $tables) {
         if (!is_arary($this->_tables)) {
             $this->tables($tables, false);
         } else {
             $tables = $this->_tables;
         }
     }
     if (!isset($tables[$tablename])) {
         return null;
     }
     $fields = array();
     $q = "DESCRIBE `" . $tablename . "`";
     foreach ($this->db->query($q) as $row) {
         $fields[$row['Field']] = $row;
     }
     return $this;
 }