-1

我想看看它是如何工作的。特别是如果它正在对“_”进行分解,或者它正在根据您传入的参数搜索路由以查找等效键。

我搜索了文档、“网络”和我的代码库,但没有太多关于它所在位置的信息。symfony 文档在构建链接时使用它。

    {# src/Acme/TaskBundle/Resources/views/Default/new.html.twig #}
    <form action="{{ path('task_new') }}" method="post" {{ form_enctype(form) }}>
        {{ form_widget(form) }}

        <input type="submit" />
    </form>

看起来它使用了路由文件中的密钥。所以下面的代码:

    {{ path('_welcome') }}

将在您的路由中寻找带有“_welcome”键的路由。

yaml

    _welcome:
        pattern:   /
        defaults:  { _controller: AcmeDemoBundle:Main:homepage }

php

    use Symfony\Component\Routing\RouteCollection;
    use Symfony\Component\Routing\Route;

    $collection = new RouteCollection();
    $collection->add('_welcome', new Route('/', array(
        '_controller' => 'AcmeDemoBundle:Main:homepage',
    )));

    return $collection;    
4

1 回答 1

3

这是定义在

https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php

它利用

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Routing/Generator/UrlGenerator.php

无论如何,我可以确认它没有在“_”上做任何爆炸

于 2012-08-06T21:04:43.603 回答