mirror of
https://github.com/anthonyaxenov/iptv.git
synced 2024-12-22 06:15:48 +00:00
Пагинация
This commit is contained in:
parent
bd1dea84d5
commit
d797ff933b
@ -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(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user