或许您可能会注意到我之前的帖子,我正在使用SF2.0.x app到新的SF2.7。现在我有很多NOTICE
并且它们不会影响应用程序功能,但它会这样做,我想阻止它。我在SF Book上阅读了Routing章,The Routing Component以及@ Route and @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
:
DEPRECATED - 自2.2版以来不推荐使用“_method”要求 并将在3.0中删除。请改用setMethods()方法或 路线定义中的“方法”选项。
现在定义路线的正确方法是什么?
答案 0 :(得分: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');