UrlGenerator::generate() 触发弃用通知

UrlGenerator::generate() triggers deprecation notice

我遇到了这个弃用错误,但我不知道它是从哪里来的。我正在使用 Symfony 2.8.2 和 CMF Routing 1.3。

这是错误:

The hardcoded value you are using for the $referenceType argument of the Symfony\Component\Routing\Generator\UrlGenerator::generate method is deprecated since version 2.8 and will not be supported anymore in 3.0. Use the constants defined in the UrlGeneratorInterface instead.  Hide stack trace

UrlGenerator::doGenerate() (called from appDevUrlGenerator.php at line 95)
appDevUrlGenerator::generate() (called from classes.php at line 1284)
Router::generate() (called from ChainRouter.php at line 231)
ChainRouter::generate() (called from WebDebugToolbarListener.php at line 68)
WebDebugToolbarListener::onKernelResponse() call_user_func() (called from WrappedListener.php at line 61)
WrappedListener::__invoke() call_user_func() (called from classes.php at line 1853)
EventDispatcher::doDispatch() (called from classes.php at line 1771)
EventDispatcher::dispatch() (called from TraceableEventDispatcher.php at line 132)
TraceableEventDispatcher::dispatch() (called from HttpKernel.php at line 179)
HttpKernel::filterResponse() (called from HttpKernel.php at line 161)
HttpKernel::handleRaw() (called from HttpKernel.php at line 62)
HttpKernel::handle() (called from ContainerAwareHttpKernel.php at line 69)
ContainerAwareHttpKernel::handle() (called from Kernel.php at line 185)
Kernel::handle() (called from app_dev.php at line 30)
require() (called from router_dev.php at line 40)

根据我的代码,我没有在任何地方调用 doGenerate()。也许 Symfony CMF 路由组件正在调用某个地方?我应该在哪里查找此错误?

您应该搜索 router->generate( 调用,其中第三个参数不是 UrlGeneratorInterface 的常量(可能在供应商代码库中)。哦,看看 http://github.com/symfony-cmf/Routing/blob/1.3.0/ChainRouter.php#L214 ... the default value is wrong so if you do not give the 3rd argument every time it will trigger a deprecation notice. It was fixed by #158,但不是稳定的版本(仅限RC),itt出来的时候是1.4。