문제

나는 fosrestbundle을 사용하고 있습니다.

나는 GET 요청을 사용하고 404 개의 오류 메시지가 기대하고 있지만, 매우 길다.

여기서는 action () 메서드의 정의입니다.

/**
 * @Rest\View
 * @Rest\Get("/api/test/{id}",
 *      requirements={"id" = "\d+"},
 *      defaults={"id" = 1}
 * )
 */
public function getAction($id) {
    $repo = $this->getDoctrine()->
            getManager()->
            getRepository("MinnAdsAPIBundle:Test");
    $entity = $repo->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find test entity!');
    }
    return array('test' => $entity);
}
.

요청을 확인하려면 다음 쉘 명령을 사용했습니다. curl -i http://localhost/tuto/web/app_dev.php/api/test/16654

결과는 다음과 같습니다.

HTTP/1.1 404 Not Found
Date: Fri, 11 Apr 2014 07:33:13 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Set-Cookie: PHPSESSID=r5fjnf14fp0oou8ac8hu60vru7; path=/
Cache-Control: no-cache
Vary: Accept-Language
X-Debug-Token: 97fd81
Transfer-Encoding: chunked
Content-Type: application/json

[{"message":"Unable to find test entity!","class":"Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"\/home\/amine\/NetBeansProjects\/tuto\/vendor\/symfony\/symfony\/src\/Symfony\/Bundle\/FrameworkBundle\/Controller\/Controller.php","line":149,"args":[]},{"namespace":"Symfony\\Bundle\\FrameworkBundle\\Controller","short_class":"Controller","class":"Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller","type":"->","function":"createNotFoundException","file":"\/home\/amine\/NetBeansProjects\/tuto\/src\/Minn\/AdsAPIBundle\/Controller\/TestController.php","line":31,"args":[["string","Unable to find test entity!"]]},{"namespace":"Minn\\AdsAPIBundle\\Controller","short_class":"TestController","class":"Minn\\AdsAPIBundle\\Controller\\TestController","type":"->","function":"getAction","file":null,"line":null,"args":[["string","155"]]},{"namespace":"","short_class":"","class":"","type":"","function":"call_user_func_array","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2841,"args":[["array",[["object","Minn\\AdsAPIBundle\\Controller\\TestController"],["string","getAction"]]],["array",[["string","155"]]]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handleRaw","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2815,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"HttpKernel","class":"Symfony\\Component\\HttpKernel\\HttpKernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2944,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\\Component\\HttpKernel\\DependencyInjection","short_class":"ContainerAwareHttpKernel","class":"Symfony\\Component\\HttpKernel\\DependencyInjection\\ContainerAwareHttpKernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/app\/bootstrap.php.cache","line":2245,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"],["string","1"],["boolean",true]]},{"namespace":"Symfony\\Component\\HttpKernel","short_class":"Kernel","class":"Symfony\\Component\\HttpKernel\\Kernel","type":"->","function":"handle","file":"\/home\/amine\/NetBeansProjects\/tuto\/web\/app_dev.php","line":29,"args":[["object","Symfony\\Component\\HttpFoundation\\Request"]]}]}]
.

내가 기대하고있는 메시지는 다음과 같습니다.

HTTP/1.1 404 Not Found
Date: Fri, 11 Apr 2014 07:33:13 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2.4
Set-Cookie: PHPSESSID=r5fjnf14fp0oou8ac8hu60vru7; path=/
Cache-Control: no-cache
Vary: Accept-Language
X-Debug-Token: 97fd81
Transfer-Encoding: chunked
Content-Type: application/json

{"message":"Unable to find test entity!"}
.

그 달성을위한 아이디어가 있습니까?

감사합니다

도움이 되었습니까?

해결책

@amine 터미널에 넣습니다.이 명령 :

curl -i http://localhost/tutonew/web/api/test/16654
.

!!!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top