class NewsController extends AbstractController
{
protected const NEWS_PER_PAGE = 5;
#[Route('/news/{page}', name: 'news', priority: 100)]
public function index(Request $request, Connection $connection, int $page = 1): Response
{
$newsCount = $connection->executeQuery("SELECT COUNT(*) FROM `news`")->fetchOne();
$totalPages = ceil($newsCount / self::NEWS_PER_PAGE);
$page = min($page, $totalPages);
$offset = $page == 1 ? 0 : ($page - 1) * self::NEWS_PER_PAGE;
$this->dispatcher->dispatch($event, KernelEvents::CONTROLLER_ARGUMENTS);
$controller = $event->getController();
$arguments = $event->getArguments();
// call controller
$response = $controller(...$arguments);
// view
if (!$response instanceof Response) {
$event = new ViewEvent($this, $request, $type, $response);
$this->dispatcher->dispatch($event, KernelEvents::VIEW);
public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true)
{
$request->headers->set('X-Php-Ob-Level', (string) ob_get_level());
try {
return $this->handleRaw($request, $type);
} catch (\Exception $e) {
if ($e instanceof RequestExceptionInterface) {
$e = new BadRequestHttpException($e->getMessage(), $e);
}
if (false === $catch) {
$this->boot();
++$this->requestStackSize;
$this->resetServices = true;
try {
return $this->getHttpKernel()->handle($request, $type, $catch);
} finally {
--$this->requestStackSize;
}
}
$this->request = $request;
}
public function run(): int
{
$response = $this->kernel->handle($this->request);
$response->send();
if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($this->request, $response);
}
$app = $app(...$args);
exit(
$runtime
->getRunner($app)
->run()
);
<?php
use App\Kernel;
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
TypeError
|
---|
TypeError: App\Controller\NewsController::index(): Argument #3 ($page) must be of type int, string given, called in /mnt/web024/d0/54/5189354/htdocs/page_neu/vendor/symfony/http-kernel/HttpKernel.php on line 152 at src/Controller/NewsController.php:19 at App\Controller\NewsController->index() (vendor/symfony/http-kernel/HttpKernel.php:152) at Symfony\Component\HttpKernel\HttpKernel->handleRaw() (vendor/symfony/http-kernel/HttpKernel.php:74) at Symfony\Component\HttpKernel\HttpKernel->handle() (vendor/symfony/http-kernel/Kernel.php:202) at Symfony\Component\HttpKernel\Kernel->handle() (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35) at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run() (vendor/autoload_runtime.php:35) at require_once('/mnt/web024/d0/54/5189354/htdocs/page_neu/vendor/autoload_runtime.php') (public/index.php:4) |