2

您可能会从我最近发布的上一篇文章中注意到,我正在将 SF2.0.x 应用程序开发为新的 SF2.7。现在我有很多,NOTICE它们不会影响应用程序的功能,但它会这样做,我想防止这种情况发生。我已阅读SF Book 中的路由章节、路由组件以及@Route 和 @Method注释,但找不到任何有助于解决问题的方法。所以我需要这里的人的帮助。现在,路线如下所示(XML 格式):

<route id="PDOneBundle_repproject_process" path="/project/{page}/{action}">
    <default key="_controller">PDOneBundle:ProjectDetail:process</default>
    <requirement key="page">\w+</requirement>
    <requirement key="action">add|update|delete</requirement>
    <requirement key="_format">html</requirement>
    <requirement key="_method">POST|GET</requirement>
</route>

下面的消息是NOTICE我得到的:

已弃用 - “_method”要求自 2.2 版以来已弃用,并将在 3.0 中删除。请改用 setMethods() 方法或路由定义中的“方法”选项。

现在定义路线的正确方法是什么?

4

1 回答 1

5

您应该阅读以下内容:

https://github.com/symfony/symfony/blob/master/UPGRADE-3.0.md

您搜索的部分:

Routing

    Some route settings have been renamed:
    The pattern setting for a route has been deprecated in favor of path
    The _scheme and _method requirements have been moved to the schemes and methods settings

Before:

article_edit:
   pattern: /article/{id}
   requirements: { '_method': 'POST|PUT', '_scheme': 'https', 'id': '\d+' }

<route id="article_edit" pattern="/article/{id}">
   <requirement key="_method">POST|PUT</requirement>
   <requirement key="_scheme">https</requirement>
   <requirement key="id">\d+</requirement>
</route>

$route = new Route();
$route->setPattern('/article/{id}');
$route->setRequirement('_method', 'POST|PUT');
$route->setRequirement('_scheme', 'https');

After:

article_edit:
   path: /article/{id}
   methods: [POST, PUT]
   schemes: https
   requirements: { 'id': '\d+' }

<route id="article_edit" path="/article/{id}" methods="POST PUT" schemes="https">
   <requirement key="id">\d+</requirement>
</route>

$route = new Route();
$route->setPath('/article/{id}');
$route->setMethods(array('POST', 'PUT'));
$route->setSchemes('https');
于 2015-04-14T16:07:34.110 回答