How to set Post Value of Request
Yes you can set value using setPostValue()
check below for set of array,
<?php
namespace Namespace\Modulename\Model;
class Request extends \Magento\Framework\DataObject
{
public function __construct(
\Magento\Framework\App\RequestInterface $request,
array $data = []
) {
$this->request = $request;
parent::__construct($data);
}
public function setPostCustomValue(){
/* for single value */
$this->request->setPostValue('test','store my value');
/* for multiple array */
$post = [
'customer' => [
'firstname' => 'test firstname',
'lastname' => 'test lastname',
'email' => '[email protected]',
'default_billing' => '_item1',
],
'address' => ['_item1' => []],
];
$this->request->setPostValue('customarray',$post);
}
You can write in you controller and it is the way worked for me:
<?php
namespace Vendor\ProductComments\Controller\Post;
use Magento\Framework\App\Action\Action;
class Index extends Action
{
public function __construct(
....
....
) {
....
....
}
public function execute()
{
$this->getRequest()->setPostValue('timestamp', '24343256534345');
}
}
You can try below code to set param
$this->getRequest()->setParam('value',$value);