0
0
mirror of https://github.com/anthonyaxenov/iptv.git synced 2024-11-22 05:24:45 +00:00

Пагинация

This commit is contained in:
Anthony Axenov 2022-09-03 16:13:03 +08:00
parent bd1dea84d5
commit d797ff933b
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
3 changed files with 33 additions and 3 deletions

View File

@ -21,17 +21,26 @@ class HomeController extends Controller
/**
* @throws Exception
*/
public function index()
public function index(int $page = 1)
{
if (Flight::request()->query->count() > 0) {
$id = Flight::request()->query->keys()[0];
Flight::redirect(base_url("$id"));
Flight::redirect(base_url($id));
die;
}
$per_page = 10;
$list = $this->ini->playlists
->where('redirect_id', null)
// ->sortBy('id')
->forPage($page, $per_page);
view('list', [
'updated_at' => $this->ini->updatedAt(),
'count' => $this->ini->playlists->count(),
'playlists' => $this->ini->playlists->where('redirect_id', null)->toArray(),
'pages' => [
'count' => (int)($this->ini->playlists->count() / $per_page),
'current' => $page,
],
'playlists' => $list->toArray(),
]);
}

View File

@ -53,6 +53,10 @@ final class Bootstrapper
'GET /',
fn() => (new HomeController())->index()
);
Flight::route(
'GET /page/@page:[0-9]+',
fn($page) => (new HomeController())->index((int)$page)
);
Flight::route(
'GET /faq',
fn() => (new HomeController())->faq()

View File

@ -54,6 +54,23 @@
{% endfor %}
</tbody>
</table>
{% if pages.count > 0 %}
<nav aria-label="pages">
<ul class="pagination pagination-sm justify-content-center">
{% for page in range(1, pages.count) %}
{% if page == pages.current %}
<li class="page-item active" aria-current="page">
<span class="page-link">{{ page }}</span>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="{{ base_url('page/' ~ page) }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
</nav>
{% endif %}
{% endblock %}
{% block footer %}