2017-10-25 1 views
1

슬림 3 프레임 워크를 백엔드로 사용하고 있으며 자체 작성 프론트 엔드 (jQuery)를 사용하고 있습니다. 내 프론트 엔드에는 내 REST 서버를 호출하는 ajax 명령이 있습니다. 이제 HTTP 요청 방법 (GET)과 일치하지 않기 때문에 클라이언트에서 DELETE을 사용할 수 없다는 문제가 있습니다. 요청이 일치하지 않아 Slim 3에서 오류가 발생했습니다. uri & request method

If your Slim Framework application has a route that matches the current HTTP request URI but NOT the HTTP request method, the application invokes its Not Allowed handler and returns a HTTP/1.1 405 Not Allowed response to the HTTP client.

가 지금은 GET 또는 PUT를 사용할 수 있지만, 이미 다른 작업에 대해 선언하는 경로를 가지고 있기 때문에 그 가능성이되지 않습니다 :

405 Method not allowed. Must be one of: GET, PUT 

공식 문서는 기본적으로 허용되지 않습니다 말했다 말한다.

Slim Application Error: The application could not run because of the following error: Details Type: FastRoute\BadRouteException Message: Static route /api/v1/folders/ is shadowed by previously defined variable route /api/v1/folders/(.*) for method GET

// Folder routes 
$this->group('/folders', function() { 
    $this->get('[/{params:.*}]', 'FolderController:index'); 
    $this->post('', 'FolderController:create'); 
    $this->put('[/{params:.*}]', 'FolderController:update'); 
    $this->delete('/[/{params:.*}]', 'FolderController:delete'); 
})->add('AuthenticateMiddleware'); 

당신은 나에게이 문제를 해결하는 방법에 대한 조언을 전해 주 시겠어요? 슬림 3처럼 작동하고 을 사용하려는 특정 상황에서 405 Method not allowed 오류가 발생하지만 브라우저에서 클릭을 할 수 없기 때문에 REST 세계에서 일반적으로 문제가되지 않습니까? GET입니까? 내 의견으로 당

+0

링크를 클릭 할 때 실패한 요청이 발생합니까? ? Slim이 올바른 컨트롤러를 호출하려면 요청 메소드가 'DELETE'여야합니다. 또한 삭제 경로에는 여분의'['' –

+1

@AlexandruUngureanu가 있습니다. 내가''을 제거한 후에는 내 독수리''DELETE'로 작업하기 때문에 독수리 눈이 생겼습니다. 작은 게시물을 작성하면 답변을 수락하겠습니다! 고맙습니다! – Magiranu

답변

1

:

Is the failing request happening when you click on a link? <a></a> ? The request method has to be DELETE in order for Slim to invoke the right controller. Also note that your delete route has an extra [

행운을 빕니다!

관련 문제