DI nefunguje v Error4×xPresenter
- japlavaren
- Člen | 404
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');
}
}
?>
- japlavaren
- Člen | 404
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');
}
}
?>