search

Home  >  Q&A  >  body text

php - In Phalcon 1.x, the getPatch() method is missing. How to obtain the data submitted during PATCH?

At work, we need to build an API based on RESTful style. When the http method is equal to PATCH, there is no $this->request->getPatch() method. Use Neither $this->request->getPut() nor $this->request->getPost() can obtain the submitted data.

Is there any way to easily obtain patch data?

PHP中文网PHP中文网2766 days ago505

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:07:23

    I didn’t find a solution online, so I implemented it myself based on phalcon’s request objectgetPatch()hasPatch().

    Specific usage:

    // get all patch data...
    $params = $this->request->getPatch(); 
      
    // try to get username from patch data
    $name = $this->request->getPatch('username');   
    
    // try to get and format price
    $price = $this->request->getPatch('price', 'float!'); 

    You only need to inject your own Request class into the dependency to call the getPatch() method in the project

    $di->set('request', function() {
        return new \Request();
    }, true);

    The specific code is on Github:

    https://github.com/baohanddd/...

    reply
    0
  • Cancelreply