Symfony2.8. How to get data from post request

前端 未结 3 1072
孤独总比滥情好
孤独总比滥情好 2021-01-02 14:58

How can I receive data from POST request in my controller? I don\'t use twig.

public function newAction(Request $request)
{
   //when I use
   $content = $re         


        
相关标签:
3条回答
  • 2021-01-02 15:11

    $request->request->get('content');

    POST: $request->request->get('<propertyName>');

    GET: $request->query->get('<propertyName>');

    0 讨论(0)
  • 2021-01-02 15:19

    You can use for POST request :

    $request->request->get('data');
    

    For GET request:

    $request->query->get('data');
    

    For FILE queries:

    $request->files.
    

    And ask your questions How to save image?, you must create uploads -> excels:

    $dir = $this->get('kernel')->getRootDir() . '/../web/uploads/images/';
    $name = uniqid() . '.jpeg';
    
    foreach ($request->files as $uploadedFile) {
        $uploadedFile->move($dir, $name);
    }
    $file = $this->get('kernel')->getRootDir() . "/../web/uploads/images/" . $name;
    
    if (file_exists($file)) {
        echo "Successfully saved";
    }
    
    0 讨论(0)
  • 2021-01-02 15:26

    Dump all data from request to find possible problem with: $request->request->all();

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