Autor Zpráva
bitks
Profil *
Zdravím prosím vás, jak mám registrovat model QuestionManager ? Debugger mi hlásí následovné:
Service 'application.3': Service of type App\Model\QuestionManager needed by App\Presenters\HomepagePresenter::__construct() not found. Did you register it in configuration file?

QuestionManager.php umístěný v app/model
namespace App\Model;

use Nette;

class QuestionManager {

    use \Nette\SmartObject;

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

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

    public function getQuestionOfDay() {
        return $this->database->table('questions')
                        ->order('id DESC')
                        ->limit(1);
    }

}
HomepagePresenter.php umístěný v app/presenters
namespace App\Presenters;

use Nette,
    Nette\Application\UI\Form;
use App\Model\QuestionManager;

class HomepagePresenter extends Nette\Application\UI\Presenter {

    /** @var QuestionManeger */
    private $questionManager;

    function __construct(QuestionManager $questionManager) {
        $this->questionManager = $questionManager;
    }

    public function renderDefault() {
        $this->template->dayQuestion = $this->questionManager->getQuestionOfDay();
    }
      }

A config.neon
parameters:


application:
    errorPresenter: Error
    mapping:
        *: App\*Module\Presenters\*Presenter


session:
    expiration: 14 days


services:
    router: App\RouterFactory::createRouter
- App\Model\QuestionManager

MOCKRÁT DĚKUJI !


už jsem na to přišel... config.local.neon

services:
        - App\Model\QuestionManager
        router: App\RouterFactory::createRouter
CZechBoY
Profil
nee do config.local.neon nedávej služby.
chybí ti odsazení u tý služby v config.neon
services:
    router: App\RouterFactory::createRouter
    - App\Model\QuestionManager

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: