2

I have 2 custom table and from admin side I want to save few field values to these 2 custom table while clicking Save button. For example in adminside I have Status option and Message option. The Status option value need to be in custom table 1 and message in custom table 2. How can I do this in Magento 2. I have Save.php file in Controller/Adminhtml/Manage folder.

Teja Bhagavan Kollepara
  • 3,816
  • 5
  • 32
  • 69
Bridgit Thomas
  • 165
  • 5
  • 16

1 Answers1

1

Your controller constructor would be like

public function __construct(Action\Context $context,Package\Module\Model\Model1 $model1 , Package\Module\Model\Model2 $model2)
{
    $this->model1 = $model1;
    $this->model2 = $model2;
    parent::__construct($context);
}


public function execute()
{
    $data = $this->getRequest()->getPostValue(); 
    $this->model1->setData('fieldname',$data['status']);
    $this->model1->save();

    $this->model2->setData('fieldname',$data['messageOption']);
    $this->model2->save();
} 
Murtuza Zabuawala
  • 14,814
  • 9
  • 44
  • 75