is not used any more and exists only for history. Post new tickets on the Github account. n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#656 closed enhancement (fixed)

jIRestController must be PUT friendly

Reported by: greut Owned by: laurentj
Priority: low Milestone: Jelix 1.2 beta
Component: jelix:core request Version: 1.0.5
Severity: normal Keywords:
Cc: Blocked By:
Blocking: Documentation needed: no
Hosting Provider: Php version:


You cannot gets the params send with a PUT call from the jController usual $this->param("..."); without this little hack. Can you consider moving this into jController? (It's only required for PUT, yeah PHP isn't that REST friendy ;-D)


class restCtrl extends jController implements jIRestController {

    function put(){
        $_PUT = array();
        parse_str(file_get_contents("php://input"), $_PUT);
        $this->request->params = array_merge($this->request->params, $_PUT);


Thanks a lot.

Attachments (2)

656_v1.diff (2.9 KB) - added by laurentj 13 years ago.
premiere version du patch
656_v2.diff (2.6 KB) - added by greut 13 years ago.
petit correctif, de la première version du patch (qui ne casse pas mon application existante)

Download all attachments as: .zip

Change History (10)

comment:1 Changed 13 years ago by greut

  • Summary changed from JIRestController must be PUT friendly to jIRestController must be PUT friendly

I've ended up with a more complex hack, since the REST client is using curl (from PHP) and sends a multipart/form-data within the body.

// […]
    function put() {
        $_PUT = array();
        $input = file_get_contents("php://input");
        if(strpos($_SERVER["CONTENT_TYPE"], "multipart/form-data") > -1) {
            list($_, $boundary) = explode("=", $_SERVER["CONTENT_TYPE"], 2);
            $vars = explode($boundary, $input);
            foreach($vars as $var) {
                $var = trim($var);
                if($var !== "--") {
                    list($name, $value) = explode("\r\n\r\n", $var);
                    if(preg_match('/.*?name="([^"]+)"/i', $name, $matches)) {
                        $_PUT[$matches[1]] = $value;
        } else {
            parse_str($input, $_PUT);
        $this->request->params = array_merge($this->request->params, $_PUT);

But this is so ugly that I think I'm doin' it wrong.

Changed 13 years ago by laurentj

premiere version du patch

comment:2 Changed 13 years ago by laurentj

  • Component changed from jelix:controllers to jelix:core request
  • Owner set to laurentj
  • Priority changed from normal to low

I've just create a first patch which is a better integration into Jelix than your's.

However, The parsing of a multipart/form-data content is not a full implementation of the specification (RFC 2388), so we have to improve it. It could be interesting to support files into multipart/form-data, so files could be handled like PHP does for POST (content saved in temporary files, and $_FILES is filled with informations of this files).

For the gold edition, perhaps we can create a function in the PHP extension of Jelix, which could call the internal API of the PHP engine, which parses multipart/form-data contents.

Another point on which I should study: should we have a specific request object to support REST or not...

comment:3 Changed 13 years ago by laurentj

  • Type changed from bug to enhancement

Changed 13 years ago by greut

petit correctif, de la première version du patch (qui ne casse pas mon application existante)

comment:4 Changed 13 years ago by greut

Thanks a lot, I can clean up a little my application now.

To have it working properly, I had to adapt the fix made to jClassicRequest a little bit (attachment:656_v2.diff)

To fully supporting the RFC, it could be interesting to have proper tests for that. This is deffo something nice to have. I don't think getting $_PUT is tied to REST only and I didn't make other funky workaround to have something that work.


-- Yoan

PS: s/Greut/Yoan Blanc/g ;-)

comment:5 Changed 13 years ago by laurentj

  • Milestone set to Jelix 1.2

comment:6 Changed 12 years ago by laurentj

  • Resolution set to fixed
  • Status changed from new to closed

comment:7 Changed 12 years ago by laurentj

  • Documentation needed set
Note: See TracTickets for help on using tickets.