Routing in Silex/Symfony. Providing a default route

前端 未结 2 1688
傲寒
傲寒 2021-02-04 14:18

I\'m attempting to do something using Silex (which uses the Symfony routing component - so the answer may be applicable to Symfony as well)

I am adding Silex to a legacy

相关标签:
2条回答
  • 2021-02-04 14:59

    You can use the error handling, with something like that :

    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpKernel\Exception\HttpException;
    use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
    
    $app->error(function (\Exception $e) use ($app) {
    if ($e instanceof NotFoundHttpException) {
            return new Response('The requested page could not be found. '.$app['request']->getRequestUri(), 404);
        }
        $code = ($e instanceof HttpException) ? $e->getStatusCode() : 500;
        return new Response('We are sorry, but something went terribly wrong.', $code);
    });
    
    0 讨论(0)
  • 2021-02-04 15:01

    I found the answer within the symfony cookbook...

    http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html

    $app->match('{url}', function($url){
        //do legacy stuff
    })->assert('url', '.+');
    
    0 讨论(0)
提交回复
热议问题