Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
7 
11 
13 {
17  public function execute()
18  {
19  $id = $this->getRequest()->getParam('id');
21  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
22  if ($id) {
23  try {
24  $model = $this->_objectManager->create(\Magento\Search\Model\Query::class);
25  $model->setId($id);
26  $model->delete();
27  $this->messageManager->addSuccessMessage(__('You deleted the search.'));
28  $resultRedirect->setPath('search/*/');
29  return $resultRedirect;
30  } catch (\Exception $e) {
31  $this->messageManager->addErrorMessage($e->getMessage());
32  $resultRedirect->setPath('search/*/edit', ['id' => $this->getRequest()->getParam('id')]);
33  return $resultRedirect;
34  }
35  }
36  $this->messageManager->addErrorMessage(__('We can\'t find a search term to delete.'));
37  $resultRedirect->setPath('search/*/');
38  return $resultRedirect;
39  }
40 }
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13