Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Save.php
Go to the documentation of this file.
1 <?php
8 
16 {
22  public function execute()
23  {
24  $variable = $this->_initVariable();
25  $data = $this->getRequest()->getPost('variable');
26  $back = $this->getRequest()->getParam('back', false);
28  $resultRedirect = $this->resultRedirectFactory->create();
29  if ($data) {
30  $data['variable_id'] = $variable->getId();
31  $variable->setData($data);
32  try {
33  $variable->save();
34  $this->messageManager->addSuccess(__('You saved the custom variable.'));
35  if ($back) {
36  $resultRedirect->setPath(
37  'adminhtml/*/edit',
38  ['_current' => true, 'variable_id' => $variable->getId()]
39  );
40  } else {
41  $resultRedirect->setPath('adminhtml/*/');
42  }
43  return $resultRedirect;
44  } catch (\Exception $e) {
45  $this->messageManager->addError($e->getMessage());
46  return $resultRedirect->setPath('adminhtml/*/edit', ['_current' => true]);
47  }
48  }
49  return $resultRedirect->setPath('adminhtml/*/');
50  }
51 }
__()
Definition: __.php:13
$variable
Definition: variable.php:7