php - 在Phalcon 1.x 中,缺少getPatch()的方法,如何获得PATCH时提交的数据呢?
PHP中文网
PHP中文网 2017-05-16 13:05:23
0
1
474

工作中需要构建基于RESTful风格的API, 当http method等于PATCH时,没有$this->request->getPatch()方法,用$this->request->getPut()或者$this->request->getPost()都没法获取提交上来的数据。

有没有方法能方便的获取到patch data呢?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
phpcn_u1582

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/...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!