我創建了轉換URI來routenames與參數
我想搭上不存在的URI,但得到500錯誤和異常Symfony2中不能趕上ResourceNotFoundException
<?php
namespace OOOO\AdvertisingBundle\Utilities;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Router;
class RouteConverter
{
private $router;
public function __construct(Router $router)
{
$this->router = $router;
}
public function uriToRoute($uri)
{
try {
$matched = $this->router->match($uri);
} catch (Exception $e) {
return null;
}
$result['name'] = $matched['_route'];
unset($matched['_route']);
unset($matched['_controller']);
$result['parameters'] = $matched;
return $result;
}
public function generateRoute($name, $parameters)
{
try {
$matched = $this->router->generate($name, $parameters, UrlGeneratorInterface::RELATIVE_PATH);
} catch (Exception $e) {
return null;
}
return $matched;
}
}
你能告訴你的php日誌?你不應該使用異常,所以你應該捕獲(\ Exception $ e) – ziollek