ErrorPresenter vypsani chyby např 404 do layoutu
- t0x1c
- Člen | 151
Ahoj chci se zeptat. Už dlouho se v tom param a nakonec jsem se rozhodl sem napsat. Snažím se když například užvatel zadá špatnou url webu aby mu to vypsalo chybu 404. Mym zámeřem je aby se chyba vypsala do layoutu meho webu. Teď mi to děla nějake podivnosti vypíše se do layoutu ale uplně divně proste se nevypiše celý web viz http://csgo-trade.net/d . Do chyby se prostě nevypisuje ani to co je v 404.latte jenom title
ErrorPresenter
<?php
use Nette\Diagnostics\Debugger;
/**
* Error presenter.
*/
class ErrorPresenter extends BasePresenter
{
/**
* @param Exception
* @return void
*/
public function renderDefault($exception)
{
if ($this->isAjax()) { // AJAX request? Just note this error in payload.
$this->payload->error = TRUE;
$this->terminate();
} elseif ($exception instanceof Nette\Application\BadRequestException) {
$code = $exception->getCode();
// load template 403.latte or 404.latte or ... 4xx.latte
$this->setView(in_array($code, array(403, 404, 405, 410, 500)) ? $code : '4xx');
// log to access.log
Debugger::log("HTTP code $code: {$exception->getMessage()} in {$exception->getFile()}:{$exception->getLine()}", 'access');
} else {
$this->setView('500'); // load template 500.latte
Debugger::log($exception, Debugger::ERROR); // and log exception
}
}
}
404.latte
{layout '../@layout.latte'}
{block #content}
<h1>Server Error</h1>
<p>We're sorry! The serdver encountered an internal erroggr and
was unable to complete your request. Please try again later.</p>
<p><small>error 404</small></p>
dasda
RSS tématu
Téma zavřeno