少し弱い前PHPとMVCの学習を始めました。だから、私は単純なプロジェクトを始めて、ページネーションの問題に悩まされていました。私は私のウェブサイトのページネーションに最適なソリューションを見つけるために助けが必要です。私が見つけたページングの例では、SQL SELECT LIMITを使ってページ番号を付けていますが、私の場合はそれほど論理的ではないようです。LIMITなしのページ分割
私がBooksControllerています
<?php
require 'Database/Connection.php';
require 'Database/QueryBuilder.php';
require 'Database/Book.php';
class BooksController
{
public function index()
{
$config = require 'config.php';
$books = new QueryBuilder(Connection::make($config['database']));
$books = $books->selectAll('books_table');
require 'views/listofbooks.view.php';
}
public function about()
{
$config = require 'config.php';
$books = new QueryBuilder(Connection::make($config['database']));
$bookId = $_REQUEST['id'];
$book = $books->selectByID('books_table', $bookId);
require 'views/aboutbook.view.php';
}
public function search()
{
$config = require 'config.php';
$books = new QueryBuilder(Connection::make($config['database']));
$text = $_REQUEST['search'];
$books = $books->search('books_table', $text);
require 'views/listofbooks.view.php';
}
}
そしてListOfBooksビュー:
<!DOCTYPE html>
<html>
<head>
\t <title>Books</title>
\t <link rel="stylesheet" type="text/css" href="styles/styles.css">
\t <script src="styles/sorttable.js"></script>
<script>sorttable.sort_alpha = function(a,b) { return a[0].localeCompare(b[0], 'lt'); }</script>
</head>
<body>
\t <form action="/search" name="search" method="GET">
\t \t <input type="text" id="textbox" size="30" name="search" placeholder="Text" required />
<input type="submit" id="button">
\t </form>
\t
\t <table class="sortable">
\t \t <thead>
\t \t \t <tr>
\t \t \t \t <th scope="col">Title</th>
\t \t \t \t <th scope="col">Year</th>
\t \t \t \t <th scope="col">Author</th>
\t \t \t \t <th scope="col">Genre</th>
\t \t \t </tr>
\t \t </thead>
\t \t <tbody>
\t \t \t <?php foreach($books as $book) : ?>
\t \t \t \t <tr>
\t \t \t \t \t <td data-label="Title"><a href="/about?id=<?php echo $book->id; ?>"><?php echo $book->Title; ?></a></td>
\t \t \t \t \t <td data-label="Year"><?php echo $book->Year; ?></td>
\t \t \t \t <td data-label="Author(s)"><?php echo $book->Author; ?></td>
\t \t \t \t <td data-label="Genre"><?php echo $book->Genre; ?></td>
\t \t \t \t </tr>
\t \t \t <?php endforeach; ?>
\t \t </tbody>
\t </table>
</body>
</html>
私は私のBooksControllerを再作成するか、他のソリューションがあるを変更すべきか?