php - 在Phalcon 1.x 中,缺少getPatch()的方法,如何取得PATCH時提交的資料呢?
PHP中文网
PHP中文网 2017-05-16 13:05:23
0
1
469

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

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

PHP中文网
PHP中文网

认证高级PHP讲师

全部回覆(1)
phpcn_u1582

沒有在網路上找到解決方案,自己基於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/...

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!