Welcome Guest, Not a member yet? Register   Sign In
HOW to use PUT with ResourceController?
#2

I just looked at the IncomingRequest class. The variable $this->body should contain the value returned by 'php://input':
PHP Code:
public function __construct($configURI $uri null$body 'php://input'UserAgent $userAgent)
{
    
// Get our body from php://input
    
if ($body === 'php://input')
    {
        
$body file_get_contents('php://input');
    }
    
$this->body      = ! empty($body) ? $body null

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:
/**
 * A convenience method that grabs the raw input stream(send method in PUT, PATCH, DELETE) and decodes
 * the String into an array.
 *
 * @return mixed
 */
public function getRawInput()
{
    
parse_str($this->body$output);
    return 
$output;


In your case, getJSON() should return what you want:
PHP Code:
/**
 * A convenience method that grabs the raw input stream and decodes
 * the JSON into an array.
 *
 * If $assoc == true, then all objects in the response will be converted
 * to associative arrays.
 *
 * @param boolean $assoc   Whether to return objects as associative arrays
 * @param integer $depth   How many levels deep to decode
 * @param integer $options Bitmask of options
 *
 * @see http://php.net/manual/en/function.json-decode.php
 *
 * @return mixed
 */
public function getJSON(bool $assoc falseint $depth 512int $options 0)
{
    return 
json_decode($this->body$assoc$depth$options);


...if not, try accessing directly $this->request->body
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply


Messages In This Thread
RE: HOW to use PUT with ResourceController? - by includebeer - 12-16-2020, 03:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB