首页  >  问答  >  正文

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 天前475

全部回复(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
  • 取消回复