DI nefunguje v Error4×xPresenter

japlavaren
Člen | 404
+
0
-

ahoj,

mam error presenter a potrebujem v nom natiahnut DI zavislost. Ci pouzivam @inject anotaciu, inject metodu alebo konstruktor, nic z toho mi nefunguje (mam tam null hodnoty)

error presenter je zo sandboxu:

<?php

namespace App\Presenters;

use Nette\Application\BadRequestException;
use Nette\Application\Request;
use Nette\Application\UI\Presenter;

class Error4xxPresenter extends Presenter
{
    public function startup()
    {
        parent::startup();
        if (!$this->getRequest()->isMethod(Request::FORWARD)) {
            $this->error();
        }
    }


    public function renderDefault(BadRequestException $exception)
    {
        // load template 403.latte or 404.latte or ... 4xx.latte
        $file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
        $this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
    }
}
?>
David Matějka
Moderator | 6445
+
0
-

ukaz kod, ktery nefunguje.

japlavaren
Člen | 404
+
0
-

stiahnuty cisto novy sandbox. adresa na neexistujuci presenter /abc – dostavam BadRequestException. ked vypnem debug mod tak mi to normalne vykresli, ale v injecnutom mailery mam null:

<?php

namespace App\Presenters;

use Nette;
use Nette\Mail\IMailer;


final class Error4xxPresenter extends Nette\Application\UI\Presenter
{
    /** @var IMailer @inject */
    public $mailer;

	public function startup()
	{
		parent::startup();
		if (!$this->getRequest()->isMethod(Nette\Application\Request::FORWARD)) {
			$this->error();
		}
	}


	public function renderDefault(Nette\Application\BadRequestException $exception)
	{
	    var_dump($this->mailer);

		// load template 403.latte or 404.latte or ... 4xx.latte
		$file = __DIR__ . "/templates/Error/{$exception->getCode()}.latte";
		$this->template->setFile(is_file($file) ? $file : __DIR__ . '/templates/Error/4xx.latte');
	}
}
?>
Milo
Nette Core | 1283
+
0
-

Nemáš vypnuté opcache.save_comments ? Zkus inject přes constructor.

David Matějka
Moderator | 6445
+
+1
-

a smazal si cache?

japlavaren
Člen | 404
+
0
-

vyriesene… bola to cache…