Hi,
I’ve just got started with Slim, looks great so far but I see there’s loads to learn.
I’ve worked my way through this tutorial and got it all working:
Now I want to try doing a few things myself. I thought I’d try something easy and create my own error page. I found this tutorial:
https://akrabat.com/custom-error-rendering-in-slim-4/
It didn’t go as well as I hoped.
I created the renderer in:
/src/Error/Renderer/HtmlErrorRenderer.php
My /config/middleware.php:
<?php
use Slim\App;
use Slim\Middleware\ErrorMiddleware;
use Selective\BasePath\BasePathMiddleware;
use App\Error\Renderer\HtmlErrorRenderer;
return function (App $app) {
// Parse json, form data and xml
$app->addBodyParsingMiddleware();
// Add the Slim built-in routing middleware
$app->addRoutingMiddleware();
//$app->setBasePath('/');
$app->add(BasePathMiddleware::class); // <--- here
// Catch exceptions and errors
$app->add(ErrorMiddleware::class);
/*
// tried the lines below instead of the line above - no luck
$errorMiddleware = $app->addErrorMiddleware(false, true, true);
$errorHandler = $errorMiddleware->getDefaultErrorHandler();
$errorHandler->registerErrorRenderer('text/html', HtmlErrorRenderer::class);
*/
};
I also tried using this code within the container but that didn’t work.
Can anyone help me with this? I’m thinking the container is a better place for this but I couldn’t wrong entirely.
Thank you!