HOW to use PUT with ResourceController? |
OK, this has been driving me absolutely nuts for a day now.
Can someone please explain to me HOW I could send a PUT request and have it accept an ID and DATA in json-format? WHAT would the route look like? WHAT would the update method look like – WHAT parameters does it need in order to JUST WORK with the "built in" update method on the Model (as is claimed in the docs)? HOW would I SEND the data to the Model in the right format ($request->getRawInput() is of no use at all)? I simply cannot find this information in a clear an understandable way in the docs, or online for that matter. Code: ROUTE: $routes->put('api/(:segment )/(:any)', 'Api::update/$1/$2'); Controller method update: Code: public function update ($resource = null, $id = null)
I just looked at the IncomingRequest class. The variable $this->body should contain the value returned by 'php://input':
PHP Code: public function __construct($config, URI $uri = null, $body = 'php://input', UserAgent $userAgent) In my opinion, getRawInput() should return $this->body without modification, but instead it return the data using parse_str(), which I think is a little weird: PHP Code: /** In your case, getJSON() should return what you want: PHP Code: /** ...if not, try accessing directly $this->request->body
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |