首頁  >  問答  >  主體

php - 在Phalcon 1.x 中,缺少getPatch()的方法,如何取得PATCH時提交的資料呢?

工作需要建立基於RESTful風格的API, 當http method等於PATCH時,沒有$this->request->getPatch()方法,用$this->request->getPut() $this->request->getPost()都沒辦法取得提交上來的資料。

有沒有方法能方便的取得到patch data呢?

PHP中文网PHP中文网2713 天前477

全部回覆(1)我來回復

  • phpcn_u1582

    phpcn_u15822017-05-16 13:07:23

    沒有在網路上找到解決方案,自己基於phalcon的request物件實作了getPatch()hasPatch()

    具體的用法:

    // 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!'); 

    只需要在依賴注入自己的Request class,就可以在專案中呼叫getPatch()方法

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

    具體的程式碼在Github:

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

    回覆
    0
  • 取消回覆