Custom 404 page with Silex not showing in prod configuration

I'm a little scared trying to display a custom 404 error page using the Silex microstructure .

My project is configured as follows:

  • the index.php page appeared to work in production mode , loading the configuration fileprod.php
  • got index_dev.php to run in debug mode . It also uses the configuration file prod.php, but some parameters are overridden by the file dev.php, for example $app['debug'], which is set to true .

Thus, basically the configuration is the same.

I defined an error handler as follows:

$app->error(function (\Exception $e, $code) use ($app) {

    // commented for testing purposes
    /*if ($app['debug']) {
        return;
    }*/

    if ($code == 404) {

        $loader = $app['dataloader'];
        $data = array(
            'global' => $loader->load('global'),
            'common' => $loader->load('common', $app['locale']),
            'header' => $loader->load('header', $app['locale']),
            'footer' => $loader->load('footer', $app['locale'])
        );

        return new Response( $app['twig']->render('404.html.twig', array( 'data' => $data )), 404);
    }

    return new Response('We are sorry, but something went terribly wrong.', $code);

});

http://localhost:8888/index_dev.php/my-non-existing-page, 404 , .

http://localhost:8888/my-non-existing-page 404- , 404!

. , . , .

+5
1

index.php. , .

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L,QSA]
+3

All Articles