Receive Post Parameters In Magento 2 Controller
To get Post data in controller you need to use following in your execute function.
public function execute()
{
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
}
If you want to get post data from controller,
$post = $this->getRequest()->getPostValue();
Here your full code,
Also You have to declare storemanager object inside __construct() function of your php file instead of use dirctly objectmanager.
I have updated your code as below,
class Index extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\App\Cache\TypeListInterface
*/
protected $_cacheTypeList;
/**
* @var \Magento\Framework\App\Cache\StateInterface
*/
protected $_cacheState;
/**
* @var \Magento\Framework\App\Cache\Frontend\Pool
*/
protected $_cacheFrontendPool;
/**
* @var \Magento\Framework\View\Result\PageFactory
*/
protected $resultPageFactory;
/**
* @param Action\Context $context
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
* @param \Magento\Framework\App\Cache\StateInterface $cacheState
* @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
*/
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
\Magento\Framework\App\Cache\StateInterface $cacheState,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
$this->storeManager = $storeManager;
}
/**
* Flush cache storage
*
*/
public function execute()
{
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
echo "<pre>";
print_r($post);
exit;
}
}