コード例 #1
0
ファイル: BlogController.php プロジェクト: stixlink/frm
 public function actionIndex()
 {
     $this->view->titlePage = "Список постов";
     $criteria = ['where' => 'active=:active', 'order' => 'date_update DESC'];
     $params = [':active' => 1];
     $pageSize = 2;
     $pagination = new core\Pagination(Post::instance(), $criteria, $params, $pageSize);
     $criteria['limit'] = $pagination->getLimit();
     $posts = Post::instance()->findAll($criteria, $params);
     $params = ['posts' => $posts, 'pagination' => $pagination->getPaginate()];
     if (Request::isAjax()) {
         echo $this->view->render("index", $params, false, false);
         exit;
     } else {
         $this->view->render("index", $params);
     }
 }
コード例 #2
0
 public function paginate($per_page = 10, $page_identifier = "page_id")
 {
     global $wpdb;
     $table = self::getTableName();
     $className = get_called_class();
     $models = array();
     $class = get_class($this);
     $count = 0;
     $page = isset($_GET[$page_identifier]) ? $_GET[$page_identifier] : 1;
     $offset = ($page - 1) * $per_page;
     $query = "select * from {$table} " . $this->generateWhere();
     $countQuery = "select count(id) from {$table} " . $this->generateWhere();
     $query = rtrim($query, "where ");
     $countQuery = rtrim($countQuery, "where ");
     $query .= " limit {$per_page} offset {$offset}";
     // dd($query);
     $results = $wpdb->get_results($query, ARRAY_A);
     $count = $wpdb->get_var($countQuery, 0, 0);
     foreach ($results as $result) {
         $models[] = new $class($result);
     }
     $this->query = $query;
     // dd($query);
     return Pagination::make($models, $page, ceil($count / $per_page), $page_identifier);
 }