5

I have added a massaction to the sales order grid in Magento 2. I want to pass on the POST data (the checked orders) to my custom controller/page which is setup and working as expected.

How do I retrieve the POST data in my controller or on the page. I searched allot but cannot find tutorials or examples. I know i can do $this->getRequest()->getPost(). But that only applies when the action is extending Magento\Framework\App\Action\Action but as far as I know this is only for frontend actions. My class is extending \Magento\Backend\App\Action as it needs to be a backend action.

Any extensive documentation or other resources on this topic would also be great!

EDIT: This was follow up question in looking for an answer. It might help users with the same problem: Magento 2 how to pass order id's from sales order grid to my module controller

7

$this->getRequest()->getParams(); will get you the post data. If you want to access a specific parameter you can use $this->getRequest()->getParam('something'); I have tested this on an admin controller and it will work when extending \Magento\Backend\App\Action

| improve this answer | |
  • Thanks, this is working indeed. Altough I was expecting data from the sales grid checkboxes. Am I think wrong? How can I retrieve the checked order id's? – Akif Jan 9 '16 at 22:45
  • You must be sending the wrong payload. You're controller will only receive the data you send it. If you are sending post data from a form, your controller will receive the value of each input in the form being submitted. I haven't done much with grids yet so I'm not sure what the fields are. – Nathan Toombs Jan 9 '16 at 23:10
  • 1
    Can you guide me with a more extensive approach/answer? I don't know how to get the checked order id's into my own extension. – Akif Jan 19 '16 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.