'또는'경로에서 어떻게 할 수 있습니까?Slim 3 - 경로에서 or 연산자를 사용하는 방법?
예를 들어, /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
});
은 이걸로 시도 :
Type: FastRoute\BadRouteException
Message: Cannot use the same placeholder "url" twice
File: /var/www/mysite/vendor/nikic/fast-route/src/DataGenerator/RegexBasedAbstract.php
모든 아이디어를 어떤 방법이 문제를 해결하려면 :
$app->get('/{url:[a-zA-Z0-9\-]+}|/{language:[fr|en]+}/{url:[a-zA-Z0-9\-]+}', function (Request $request, Response $response, array $args) {
// same staff
});
나는이 오류가?
또는 해결 방법 코드를 반복 하시겠습니까?
마지막 경로 패턴에서 오류가 발생했습니다. url을 두 번 참조합니다 ... 동일한 토큰을 두 번 사용하지 않아도됩니다. – geggleto
@geggleto 코드 반복을 피하는 해결책은 무엇입니까? – laukok
코드를 중복시키지 않으려면 http://www.slimframework.com/docs/objects/router.html#container-resolution – danopz