我怎样才能在路线上做“或”?
例如,/about
并且/fr/about
指向相同的对象/类/方法。所以而不是:
$app->get('/{url:[a-zA-Z0-9\-]+}', function (Request $request, Response $response, array $args) {
// same staff
});
$app->get('/{language:[fr|en]+}/{url:[a-zA-Z0-9\-]+}', function (Request $request, Response $response, array $args) {
// same staff
});
我试过这个:
$app->get('/{url:[a-zA-Z0-9\-]+}|/{language:[fr|en]+}/{url:[a-zA-Z0-9\-]+}', function (Request $request, Response $response, array $args) {
// same staff
});
我收到此错误:
Type: FastRoute\BadRouteException
Message: Cannot use the same placeholder "url" twice
File: /var/www/mysite/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php
任何想法如何解决这个问题?
或任何避免重复代码的解决方案?