Nastaveni služby DI v neonu

tomas_straka
Člen | 32
+
0
-

Ahoj, prosím o pomoc s nastavenim sluzby v neonu. Dostavam chybu: Service ‚application.3‘ (type of App\Presenters\FirmyPresenter): Service of type App\Model\FirmyRepository needed by $firmyRepository in __construct() not found. Did you add it to configuration file?
Coz jsem pochopil, ze jsem tlacen do DI.
Firmyrespository jsou sluzbou pro FirmyPresenter. Poskytuji udaje o firmach a trida FirmyPresenter je vypise do sablony.

<?php


namespace App\Presenters;

use App\Model\FirmyRepository;
use Nette;


class FirmyPresenter extends Nette\Application\UI\Presenter
{

    /** @var FirmyRepository */
    private $firmyRepository;

    private Nette\Database\Explorer $database;

    public function __construct(FirmyRepository $firmyRepository)
    {
        $this->firmyRepository = $firmyRepository;
    }

    public function renderFirmy()
    {

        $this->template->firmy = $this->articleRepository->findPublishedArticles();
    }


}

a

<?php


namespace App\Model;
use Nette;

class FirmyRepository
{
    use Nette\SmartObject;

    /** @var Nette\Database\Connection */
    private $database;

    public function __construct(Nette\Database\Connection $database)
    {
        $this->database = $database;
    }

    public function findPublishedArticles(int $limit): Nette\Database\ResultSet
    {
        return $this->database->query('
			SELECT * FROM articles
			ORDER BY nazev DESC
			LIMIT ?
			OFFSET ?',
            $limit
        );
    }

    /**
     * Vrací celkový počet publikovaných článků
     */
    public function getPublishedArticlesCount(): int
    {
        return $this->database->fetchField('SELECT COUNT(*) FROM firmy');
    }
}

Jak to zapsat do konfigurace? Vysledek ma byt strankovani https://doc.nette.org/…s/pagination Diky

Marek Bartoš
Nette Blogger | 1273
+
+1
-
services:
	- App\Model\FirmyRepository

Viz také https://doc.nette.org/…ion/services#…

tomas_straka
Člen | 32
+
0
-

Mabar napsal(a):

services:
	- App\Model\FirmyRepository

Viz také https://doc.nette.org/…ion/services#…

Ty jo, takhle jednoduchy to je. Moc diky. Slape