我要自定义路由UrlGenerator
以下是我的修改
File: vendor/symfony/framework-bundle/Resources/config/routing.xml
<argument key="generator_class">Symfony\Component\Routing\Generator\UrlGenerator</argument>
<argument key="generator_base_class">Symfony\Component\Routing\Generator\UrlGenerator</argument>
到
<argument key="generator_class">App\Routing\UrlGenerator</argument>
<argument key="generator_base_class">App\Routing\UrlGenerator</argument>
UrlGenerator类
<?php
namespace App\Routing;
class UrlGenerator extends \Symfony\Component\Routing\Generator\UrlGenerator
{
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = [])
{
$url = parent::doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, $requiredSchemes);
var_dump($url);
die;
}
}
控制器文件
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
/**
* @Route("/test")
*/
public function test()
{
$ret = $this->generateUrl('_profiler_exception_css', ['token' => 'test']);
var_dump($ret);
die;
}
}
他似乎是可以工作的,但是我认为这不是最好的方法,能帮帮我,如何配置,不要修改作曲家内部的代码