REST GET with parameter ignored, PHP Symfony 3 Mpdf

后端 未结 1 1681
独厮守ぢ
独厮守ぢ 2021-01-16 17:39

Working on a REST API for PDF processor using Mpdf(and tfox symfony bundle) on Symfony 3 Framework. I created two GET requests, one with no parameters for testing, and one w

相关标签:
1条回答
  • 2021-01-16 18:02

    http://localhost:8000/create?htmlSource=PATH-TO-FILE-LOCALLY

    ("/create/{htmlSource}")

    These paths do not match. First path consists of domain name, and route create, while second path has route "create" + slash + wildcard.

    Query parameters are not defined within routing annotation. Instead, access them inside controller, using

    public function createPDFFromSourceAction(Request $request)
    {
        $htmlSource = $request->query->get('htmlSource'); // query string parameter
        $somethingElse = $request->request->get('somethingElse'); //POST request parameter
        ...
    }
    

    Symfony will pass Request object inside the controller for you.

    As for your other question, GET requests are usually used for things that do not change the state of the application, and POST/PUT/PATCH/DELETE requests change the state. Since you are uploading something, use POST request.

    For your 'side note' you should ask another question instead.

    0 讨论(0)
提交回复
热议问题