Browse Source

remove page attribute from url sef routing

main
ghost 1 year ago
parent
commit
d2cb66f51d
  1. 11
      src/Controller/TorrentController.php
  2. 24
      src/Controller/UserController.php

11
src/Controller/TorrentController.php

@ -17,16 +17,11 @@ class TorrentController extends AbstractController
{ {
// Torrent // Torrent
#[Route( #[Route(
'/{_locale}/torrent/{torrentId}/{page}', '/{_locale}/torrent/{torrentId}',
name: 'torrent_info', name: 'torrent_info',
requirements: requirements:
[ [
'torrentId' => '\d+', 'torrentId' => '\d+',
'page' => '\d+',
],
defaults:
[
'page' => 1,
], ],
methods: methods:
[ [
@ -34,7 +29,6 @@ class TorrentController extends AbstractController
] ]
)] )]
public function info( public function info(
int $page,
Request $request, Request $request,
TranslatorInterface $translator, TranslatorInterface $translator,
UserService $userService, UserService $userService,
@ -94,6 +88,9 @@ class TorrentController extends AbstractController
$user->getEvents() $user->getEvents()
); );
// Init page
$page = $request->get('page') ? (int) $request->get('page') : 1;
// Render template // Render template
return $this->render('default/torrent/info.html.twig', [ return $this->render('default/torrent/info.html.twig', [
'torrent' => 'torrent' =>

24
src/Controller/UserController.php

@ -39,23 +39,14 @@ class UserController extends AbstractController
} }
#[Route( #[Route(
'/{_locale}/{page}', '/{_locale}',
name: 'user_dashboard', name: 'user_dashboard',
requirements:
[
'page' => '\d+',
],
defaults:
[
'page' => 1,
],
methods: methods:
[ [
'GET' 'GET'
] ]
)] )]
public function index( public function index(
int $page,
Request $request, Request $request,
UserService $userService, UserService $userService,
ActivityService $activityService ActivityService $activityService
@ -71,6 +62,8 @@ class UserController extends AbstractController
$user->getEvents() $user->getEvents()
); );
$page = $request->get('page') ? (int) $request->get('page') : 1;
return $this->render( return $this->render(
'default/user/dashboard.html.twig', 'default/user/dashboard.html.twig',
[ [
@ -206,22 +199,18 @@ class UserController extends AbstractController
} }
#[Route( #[Route(
'/{_locale}/profile/{userId}/{page}', '/{_locale}/profile/{userId}',
name: 'user_info', name: 'user_info',
defaults: [ defaults: [
'_locale' => '%app.locale%', '_locale' => '%app.locale%',
'userId' => 0, 'userId' => 0,
'page' => 1,
], ],
requirements: [ requirements: [
'_locale' => '%app.locales%', '_locale' => '%app.locales%',
'userId' => '\d+', 'userId' => '\d+',
'page' => '\d+',
], ],
)] )]
public function info( public function info(
int $userId,
int $page,
Request $request, Request $request,
TranslatorInterface $translator, TranslatorInterface $translator,
UserService $userService, UserService $userService,
@ -245,7 +234,7 @@ class UserController extends AbstractController
// Init target user // Init target user
if (!$userTarget = $userService->getUser( if (!$userTarget = $userService->getUser(
$userId ? $userId : $user->getId() $request->get('userId') ? $request->get('userId') : $user->getId()
)) ))
{ {
throw $this->createNotFoundException(); throw $this->createNotFoundException();
@ -257,6 +246,9 @@ class UserController extends AbstractController
$user->getEvents() $user->getEvents()
); );
// Init page
$page = $request->get('page') ? (int) $request->get('page') : 1;
// Render template // Render template
return $this->render( return $this->render(
'default/user/info.html.twig', 'default/user/info.html.twig',

Loading…
Cancel
Save