我正在從 Symfony 4 更新到 Symfony 5.4。Framework Bundle 的一項更改已RouteCollectionBuilder被棄用,取而代之的是RoutingConfigurator. 但問題是我曾經為這樣的路由設定默認要求:
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
$routes->setRequirement('_locale', 'ru|en|ua|es|fr|pl|de|pt|it|be');
但是newRoutingConfigurator沒有任何替代的方法setRequirement。如何使用新配置器為所有路由定義全域/默認要求?
另一件事是該prefix引數也消失了,所以我需要以某種方式對整個路由組使用前綴(我曾經有 3 個不同的路由組,它們具有不同的前綴)。
uj5u.com熱心網友回復:
經過一些研究后自我回答。
因此,newRoutingConfigurator::import()回傳一個ImportConfigurator類的實體,您可以在其中設定所有默認引數。
所以現在我的代碼如下所示:
$routes
->import($confDir . '/{routes}.yaml', 'glob')
->prefix('/');
$routes
->import($confDir . '/{routing}/*.yaml', 'glob')
->prefix('/{_locale}/')
->requirements(['_locale' => 'ru|en|ua|es|fr|pl|de|pt|it|be']);
$routes
->import($confDir . '/{routing}/' . $this->environment . '/*.yaml', 'glob')
->prefix('/');
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/406907.html
標籤:
