error presenter a signaly
- ali
- Člen | 342
Zdravim,
mam error presenter a error kody 403 a 404 zobrazuji v normálním webovem
layoutu, error presenter mi dedi signaly od base presenteru. V base presenteru
mam jeden spolecny signal na logout pro vsechny presentery (odkaz v menu) jenze
pri zobrazeni chyby (treba 404) tento signal nefunguje a adresa
localhost/error?do=.. konci opet na error 404.
Zajima me, jestli tento problem jde vyresit jinak, nez tak ze si vytvorim routu
na presmerovani z presenteru error na jiny presenter.
Dekuji.
- David Matějka
- Moderator | 6445
Ja mam 2 error presentery – zakladni ErrorPresenter, ktery dedi od UI\Presenteru, ma novy layout atd. A pak nejaky ErrorAltPresenter, ktery dedi od BasePresenteru, pouziva spolecny layout. Chyby smeruji na Error, ktery se pokusi provest ErrorAlt. Pokud dojde k chybe v ErrorAlt, vykresli se ten zakladni s novym layoutem. Zhruba zkracene:
class ErrorPresenter extends Nette\Application\UI\Presenter
{
/** @var Nette\Application\IPresenterFactory */
private $presenterFactory;
public function __construct(Nette\Application\IPresenterFactory $presenterFactory)
{
$this->presenterFactory = $presenterFactory;
}
public function actionDefault($exception)
{
try {
$request = new Nette\Application\Request('ErrorAlt', 'GET', $this->getParameters());
$presenter = $this->presenterFactory->createPresenter($request->getPresenterName());
$response = $presenter->run($request);
if ($response instanceof Nette\Application\Responses\TextResponse && ($source = $response->getSource()) instanceof Nette\Application\UI\ITemplate) {
$source = $source->__toString(TRUE);
$response = new Nette\Application\Responses\TextResponse($source);
}
$this->sendResponse($response);
} catch (Nette\Application\AbortException $e) {
throw $e;
} catch (\Exception $e) {
}
}
}