How To use Two models in Action Controller

by Hardik Radadiya   Last Updated August 14, 2019 08:09 AM

I have made on grid for contact, in that add new contact controller is shown below

use Magento\Backend\App\Action;
use My\Module\Model\Save as Contact;

class NewAction extends \Magento\Backend\App\Action
 * Edit A Contact Page
 * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect
 * @SuppressWarnings(PHPMD.NPathComplexity)
public function execute()

    $contactDatas = $this->getRequest()->getParam('contact');
    if(is_array($contactDatas)) {
        $contact = $this->_objectManager->create(Contact::class);
             $this->messageManager->addSuccessMessage(__('You saved the data.'));
             $this->messageManager->addErrorMessage(__('Data was not saved.'));
        $resultRedirect = $this->resultRedirectFactory->create();
        return $resultRedirect->setPath('*/*/index');

in this i have fields like firstname, lastname, phone, email, address, zipcode, country. i want to store fristname, lastname, phone, email on table my_module_contact that is working very well in this code but value of address, zipcode, and country i want in other table how to do, can any one HELP

Tags : magento2

Related Questions