如何在路由 YAML 中使用 PHP 常量

问题描述

我使用的是 Symfony 3.4

我设法让 PHP 常量为服务工作(如文档中所述)。但我不知道如何让它在路由文件中工作。这是我目前所拥有的。

实体:

namespace CompanyName\AppBundle\Entity\SomeDirectory;

class MyEntity
{
    public const STATUS__CREATED = 1;
}

routing.yml:

view_my_entity_with_status_created:
  path:       /created/
  defaults:
    _controller: "AppBundle:SomeOtherDirectory/Something:index"
    status: !php/const CompanyName\AppBundle\Entity\SomeDirectory\MyEntity::STATUS__CREATED

SomethingController

public function indexAction(?int $status = null): Response
{
 // ...
}

据我所知,!php/const 被忽略,因为状态始终为空。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)