ErrorPresenter zvlast pre modul
- duskohu
- Člen | 778
Ahojte,
Pouzivam error prezenter globalne pre vsetky moduli. Chcel by som pouzit Pre
konkretny modul DhcpModule
zvlast ErrorPresenter, je to
nejako mozne?
app
presenters
- Error4xxPresenter(Nas\Presenters)
OtherModule
FrontModule
presenters
DhcpModule
FrontModule
presenters
Error4xxPresenter(Nas\DhcpModule\FrontModule\Presenters)
application:
errorPresenter: Error
mapping:
*: Nas\*Module\Presenters\*Presenter
- jiri.pudil
- Nette Blogger | 1032
Ahoj, mělo by být možné poslouchat na Application::$onRequest
a v listeneru na základě modulu requestu změnit
$application->errorPresenter
(je public).
- F.Vesely
- Člen | 369
Pripadne si muzes v ErrorPresenteru
presmerovat na jiny jako je
to ukazano v nette/sandbox
viz https://github.com/…resenter.php#…
- duskohu
- Člen | 778
Dakujem velmi pekne. Len mam este jeden problem, ten error presenter mi nenajde.
namespace Nas\Presenters
class Error4xxPresenter extends BasePresenter
{
...
public function renderDefault($exception, Request $request = null)
{
[$module, $presenter, $sep] = \Nette\Application\Helpers::splitName($request->getPresenterName());
$errorPresenter = $module . $sep . 'Error4xx'; // Dhcp:Front:Error4xx
return new ForwardResponse($request->setPresenterName($errorPresenter));
}
}
namespace Nas\DhcpModule\FrontModule\Presenters;
class Error4xxPresenter extends BasePresenter
{
...
public function renderDefault($exception, Request $request = null)
{
bd('tu sa nedostanem');exit;
}
}
Page not found. Missing template '/var/www/html/app/themes/errorTheme/Error/default.latte'.
Editoval duskohu (13. 4. 2020 23:51)
- duskohu
- Člen | 778
Tak Bolo to zle lebo som to nerobol v ErrorPresenteru
, :-),
dik moc.
class ErrorPresenter implements IPresenter
{
use SmartObject;
/**
* @autowire
* @var \Nette\Application\IPresenterFactory
*/
protected $presenterFactory;
/**
* @param IPresenterFactory $presenterFactory
*/
public function __construct(IPresenterFactory $presenterFactory)
{
$this->presenterFactory = $presenterFactory;
}
/**
* @return IResponse
*/
public function run(Request $request)
{
$e = $request->getParameter('exception');
$eRequest = $request->getParameter('request');
if ($e instanceof BadRequestException || $e instanceof VerificationException) {
Debugger::log("HTTP code {$e->getCode()}: {$e->getMessage()} in {$e->getFile()}:{$e->getLine()}", 'access');
[$module, $sep] = Helpers::splitName($eRequest->getPresenterName());
$errorPresenter = $module . $sep . 'Error4xx';
$presenterClass = $this->presenterFactory->formatPresenterClass($errorPresenter);
if (class_exists($presenterClass)) {
return new ForwardResponse($request->setPresenterName($errorPresenter));
}
list($module, , $sep) = Helpers::splitName($request->getPresenterName());
return new ForwardResponse($request->setPresenterName($module . $sep . 'Error4xx'));
}
Debugger::log($e, ILogger::EXCEPTION);
return new CallbackResponse(
function (IRequest $httpRequest, \Nette\Http\IResponse $httpResponse) {
if (preg_match('#^text/html(?:;|$)#', $httpResponse->getHeader('Content-Type'))) {
require __DIR__ . '/../themes/errorTheme/Error/500.phtml';
}
}
);
}
}
Editoval duskohu (14. 4. 2020 9:11)