Receive Post Parameters In Magento 2 Controller












7















I am calling HTTP request for controller, I am getting get parameters, but I am not able to receive post parameters in Controller.



Basically I want to call Magento 2 APIs and send customized response to application, for that I have created a simple module, which will call API and customized response and send response to application,



But I am not able to fetch post parameters from request.



Here are some of my files which can give an idea about problem,



etc/webapi.xml



<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/api/token" method="POST">
<service class="SpaargApiApiapiInterface" method="token"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>


Index.php



<?php
/**
*
* Copyright © 2015 Spaargcommerce. All rights reserved.
*/
namespace SpaargApiControllerToken;

class Index extends MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory
) {
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
}

/**
* Flush cache storage
*
*/
public function execute()
{
//$this->resultPage = $this->resultPageFactory->create();
//return $this->resultPage;

$_objectManager = MagentoFrameworkAppObjectManager::getInstance(); //instance ofMagentoFrameworkAppObjectManager
$storeManager = $_objectManager->get('MagentoStoreModelStoreManagerInterface');
$currentStore = $storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();

$post = $this->getRequest()->getPost();

echo "<pre>";
print_r($post);
exit;

}
}


It will be great if someone can help.










share|improve this question

























  • Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

    – Ankit Shah
    Dec 12 '16 at 1:41











  • @Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

    – magefms
    3 hours ago
















7















I am calling HTTP request for controller, I am getting get parameters, but I am not able to receive post parameters in Controller.



Basically I want to call Magento 2 APIs and send customized response to application, for that I have created a simple module, which will call API and customized response and send response to application,



But I am not able to fetch post parameters from request.



Here are some of my files which can give an idea about problem,



etc/webapi.xml



<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/api/token" method="POST">
<service class="SpaargApiApiapiInterface" method="token"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>


Index.php



<?php
/**
*
* Copyright © 2015 Spaargcommerce. All rights reserved.
*/
namespace SpaargApiControllerToken;

class Index extends MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory
) {
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
}

/**
* Flush cache storage
*
*/
public function execute()
{
//$this->resultPage = $this->resultPageFactory->create();
//return $this->resultPage;

$_objectManager = MagentoFrameworkAppObjectManager::getInstance(); //instance ofMagentoFrameworkAppObjectManager
$storeManager = $_objectManager->get('MagentoStoreModelStoreManagerInterface');
$currentStore = $storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();

$post = $this->getRequest()->getPost();

echo "<pre>";
print_r($post);
exit;

}
}


It will be great if someone can help.










share|improve this question

























  • Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

    – Ankit Shah
    Dec 12 '16 at 1:41











  • @Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

    – magefms
    3 hours ago














7












7








7


1






I am calling HTTP request for controller, I am getting get parameters, but I am not able to receive post parameters in Controller.



Basically I want to call Magento 2 APIs and send customized response to application, for that I have created a simple module, which will call API and customized response and send response to application,



But I am not able to fetch post parameters from request.



Here are some of my files which can give an idea about problem,



etc/webapi.xml



<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/api/token" method="POST">
<service class="SpaargApiApiapiInterface" method="token"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>


Index.php



<?php
/**
*
* Copyright © 2015 Spaargcommerce. All rights reserved.
*/
namespace SpaargApiControllerToken;

class Index extends MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory
) {
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
}

/**
* Flush cache storage
*
*/
public function execute()
{
//$this->resultPage = $this->resultPageFactory->create();
//return $this->resultPage;

$_objectManager = MagentoFrameworkAppObjectManager::getInstance(); //instance ofMagentoFrameworkAppObjectManager
$storeManager = $_objectManager->get('MagentoStoreModelStoreManagerInterface');
$currentStore = $storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();

$post = $this->getRequest()->getPost();

echo "<pre>";
print_r($post);
exit;

}
}


It will be great if someone can help.










share|improve this question
















I am calling HTTP request for controller, I am getting get parameters, but I am not able to receive post parameters in Controller.



Basically I want to call Magento 2 APIs and send customized response to application, for that I have created a simple module, which will call API and customized response and send response to application,



But I am not able to fetch post parameters from request.



Here are some of my files which can give an idea about problem,



etc/webapi.xml



<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/api/token" method="POST">
<service class="SpaargApiApiapiInterface" method="token"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>


Index.php



<?php
/**
*
* Copyright © 2015 Spaargcommerce. All rights reserved.
*/
namespace SpaargApiControllerToken;

class Index extends MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory
) {
parent::__construct($context);
$this->_cacheTypeList = $cacheTypeList;
$this->_cacheState = $cacheState;
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->resultPageFactory = $resultPageFactory;
}

/**
* Flush cache storage
*
*/
public function execute()
{
//$this->resultPage = $this->resultPageFactory->create();
//return $this->resultPage;

$_objectManager = MagentoFrameworkAppObjectManager::getInstance(); //instance ofMagentoFrameworkAppObjectManager
$storeManager = $_objectManager->get('MagentoStoreModelStoreManagerInterface');
$currentStore = $storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();

$post = $this->getRequest()->getPost();

echo "<pre>";
print_r($post);
exit;

}
}


It will be great if someone can help.







magento2 php api rest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









magefms

829218




829218










asked Dec 11 '16 at 6:38









AnandAnand

1191214




1191214













  • Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

    – Ankit Shah
    Dec 12 '16 at 1:41











  • @Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

    – magefms
    3 hours ago



















  • Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

    – Ankit Shah
    Dec 12 '16 at 1:41











  • @Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

    – magefms
    3 hours ago

















Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

– Ankit Shah
Dec 12 '16 at 1:41





Please check Ur form tag with method post $postParam = $this->context->getRequest()->getParam('<param>');

– Ankit Shah
Dec 12 '16 at 1:41













@Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

– magefms
3 hours ago





@Anand, could you help on how did you implement your custom api endpoint and get post params using controller? Thanks in advance

– magefms
3 hours ago










2 Answers
2






active

oldest

votes


















9














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;

}





share|improve this answer
























  • If I want to use custom method for getting post parameters then how will it possible?

    – Pratik Mehta
    Jul 3 '18 at 6:27











  • I want to give 100 upvotes to this answer

    – Murtuza Zabuawala
    Oct 15 '18 at 13:10



















1














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 MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $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;

}
}





share|improve this answer
























  • Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

    – Slimshadddyyy
    Nov 24 '17 at 6:39











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f149781%2freceive-post-parameters-in-magento-2-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














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;

}





share|improve this answer
























  • If I want to use custom method for getting post parameters then how will it possible?

    – Pratik Mehta
    Jul 3 '18 at 6:27











  • I want to give 100 upvotes to this answer

    – Murtuza Zabuawala
    Oct 15 '18 at 13:10
















9














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;

}





share|improve this answer
























  • If I want to use custom method for getting post parameters then how will it possible?

    – Pratik Mehta
    Jul 3 '18 at 6:27











  • I want to give 100 upvotes to this answer

    – Murtuza Zabuawala
    Oct 15 '18 at 13:10














9












9








9







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;

}





share|improve this answer













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;

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 12 '16 at 4:54









Salma SaiyadSalma Saiyad

72928




72928













  • If I want to use custom method for getting post parameters then how will it possible?

    – Pratik Mehta
    Jul 3 '18 at 6:27











  • I want to give 100 upvotes to this answer

    – Murtuza Zabuawala
    Oct 15 '18 at 13:10



















  • If I want to use custom method for getting post parameters then how will it possible?

    – Pratik Mehta
    Jul 3 '18 at 6:27











  • I want to give 100 upvotes to this answer

    – Murtuza Zabuawala
    Oct 15 '18 at 13:10

















If I want to use custom method for getting post parameters then how will it possible?

– Pratik Mehta
Jul 3 '18 at 6:27





If I want to use custom method for getting post parameters then how will it possible?

– Pratik Mehta
Jul 3 '18 at 6:27













I want to give 100 upvotes to this answer

– Murtuza Zabuawala
Oct 15 '18 at 13:10





I want to give 100 upvotes to this answer

– Murtuza Zabuawala
Oct 15 '18 at 13:10













1














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 MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $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;

}
}





share|improve this answer
























  • Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

    – Slimshadddyyy
    Nov 24 '17 at 6:39
















1














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 MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $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;

}
}





share|improve this answer
























  • Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

    – Slimshadddyyy
    Nov 24 '17 at 6:39














1












1








1







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 MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $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;

}
}





share|improve this answer













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 MagentoFrameworkAppActionAction
{

/**
* @var MagentoFrameworkAppCacheTypeListInterface
*/
protected $_cacheTypeList;

/**
* @var MagentoFrameworkAppCacheStateInterface
*/
protected $_cacheState;

/**
* @var MagentoFrameworkAppCacheFrontendPool
*/
protected $_cacheFrontendPool;

/**
* @var MagentoFrameworkViewResultPageFactory
*/
protected $resultPageFactory;

/**
* @param ActionContext $context
* @param MagentoFrameworkAppCacheTypeListInterface $cacheTypeList
* @param MagentoFrameworkAppCacheStateInterface $cacheState
* @param MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool
* @param MagentoFrameworkViewResultPageFactory $resultPageFactory
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkAppCacheTypeListInterface $cacheTypeList,
MagentoFrameworkAppCacheStateInterface $cacheState,
MagentoFrameworkAppCacheFrontendPool $cacheFrontendPool,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoStoreModelStoreManagerInterface $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;

}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 12 '16 at 5:10









Rakesh JesadiyaRakesh Jesadiya

29.2k1573120




29.2k1573120













  • Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

    – Slimshadddyyy
    Nov 24 '17 at 6:39



















  • Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

    – Slimshadddyyy
    Nov 24 '17 at 6:39

















Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

– Slimshadddyyy
Nov 24 '17 at 6:39





Is it possible to unset/remove post params i.e.$post = $this->getRequest()->getPostValue();

– Slimshadddyyy
Nov 24 '17 at 6:39


















draft saved

draft discarded




















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f149781%2freceive-post-parameters-in-magento-2-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Polycentropodidae

Magento 2 Error message: Invalid state change requested

Paulmy