Problem s Pagination – Return type of IPaginationControlFactory::create() is not declared
- vosy
- Člen | 532
zkouším rozchodit stránkování ale zastavil jsem se na chybě:
Service 'paginationControlFactory' (type of App\AdminModule\components\IPaginationControlFactory): Return type of IPaginationControlFactory::create() is not declared.
.neon
services:
# Componenty
paginationControlFactory:
implement: App\AdminModule\components\IPaginationControlFactory
setup:
- setRadius(%pageRadius%)
- setItemsPerPage(%itemsPerPage%)
latte
<div>
{control pagination}
</div>
presenter
use App\AdminModule\components\IPaginationControlFactory;
....
...
class EmailyPresenter extends InPresenter
{
private IPaginationControlFactory $paginationControlFactory;
public function injectPaginationControlFactory(IPaginationControlFactory $paginationControlFactory)
{
$this->paginationControlFactory = $paginationControlFactory;
}
....
....
....
public function renderSeznam()
{
...
....
...
$paginator = $this['pagination']->getPaginator();
$paginator->setItemCount(count($emails));
$paginator->setPage($this->getParameter('page',1));
// omezení počtu vypisovaných emailů
$emails->limit($paginator->getLength(), $paginator->getOffset());
// Přidání proměnných do šablony
$this->template->emails = $emails;
}
...
...
...
protected function createComponentPagination()
{
return $this->paginationControlFactory->create();
}
PaginationControl
<?php
declare(strict_types=1);
namespace App\AdminModule\components;
use Nette\Application\UI\Control;
use Nette\Utils\Paginator;
class PaginationControl extends Control
{
const
TEMPLATE = __DIR__.'/../Presenter/templates/components/pagination.latte';
private int $radius = 5;
private Paginator $paginator;
public function __construct()
{
$this->paginator = new Paginator();
}
public function setRadius($radius)
{
if (is_numeric($radius)) $this->radius = (int)$radius;
}
public function getPaginator()
{
return $this->paginator;
}
public function setItemsPerPage($itemsPerPage)
{
$this->paginator->setItemsPerPage($itemsPerPage);
}
public function render()
{
$this->template->setFile(self::TEMPLATE);
// vykreslí komponentu
$this->template->render();
}
}
interface IPaginationControlFactory
{
public function create();
}
composer.json
"require": {
"php": ">= 7.2",
"nette/application": "^3.1",
"nette/bootstrap": "^3.1",
"nette/caching": "^3.1",
"nette/database": "^3.1",
"nette/di": "^3.0",
"nette/finder": "^2.5",
"nette/forms": "^3.1",
"nette/http": "^3.1",
"nette/mail": "^3.1",
"nette/robot-loader": "^3.3",
"nette/security": "^3.1",
"nette/utils": "^3.2",
"latte/latte": "^2.9",
"tracy/tracy": "^2.8"
},
Editoval vosy (9. 10. 2022 23:55)
- Marek Bartoš
- Nette Blogger | 1280
Neřekl jsi Nette, jakou třídu má factory vyrobit
interface IPaginationControlFactory
{
public function create(): PaginationControl;
}