php - 将路线从旧格式迁移到新格式,这方面的文档在哪里?丢失的?

标签 php symfony symfony-routing symfony-2.7

也许您可能会从我最近的上一篇文章中注意到,我正在开发 SF2.0.x 应用程序到新的 SF2.7。现在我收到了很多通知,它们不会影响应用程序功能,但它会影响应用程序功能,我想防止这种情况发生。我已阅读Routing SF Book 章节,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>

下面的消息是我收到的通知:

DEPRECATED - The "_method" requirement is deprecated since version 2.2 and will be removed in 3.0. Use the setMethods() method instead or the "methods" option in the route definition.

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

最佳答案

您应该阅读以下内容:

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');

关于php - 将路线从旧格式迁移到新格式,这方面的文档在哪里?丢失的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632182/

相关文章:

PHP 禁止访问者并插入到 mySQL 数据库

php - MySQL 查询缓存用于昂贵的查询?

php - Symfony2 无法持久化有关系的列

symfony - 自适应 Symfony2 表单选择

symfony - 使用 Mink 测试时模拟服务?

php - 从 Symfony 中的路由条件表达式访问全局参数

php - 删除 symfony 路由组件中的默认语言环境前缀

php - 获取数据并将其提交到数据库

php - Angular2 和 xampp 服务器

php - Symfony 6 中的命名路由,内部目录中有 Controller