Guest User

Untitled

a guest
Jul 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 18/07/2018
  6. * Time: 1:30 CH
  7. */
  8.  
  9. namespace FuduHelloWorldControllerAdminhtmlStudent;
  10.  
  11. use MagentoFrameworkRegistry;
  12. use MagentoFrameworkViewResultPageFactory;
  13. use MagentoBackendAppActionContext;
  14. use FuduHelloWorldModelStudentsFactory;
  15. use FuduHelloWorldModelResourceModelStudents as ResourceModel;
  16.  
  17. class Create extends MagentoBackendAppAction
  18. {
  19. /**
  20. * @var StudentsFactory
  21. */
  22. protected $studentsFactory;
  23.  
  24. /**
  25. * @var ResourceModel
  26. */
  27. protected $resourceModel;
  28.  
  29. public function __construct(
  30. Context $context,
  31. Registry $coreRegistry,
  32. PageFactory $resultPageFactory,
  33. StudentsFactory $studentsFactory,
  34. ResourceModel $resourceModel
  35. ) {
  36.  
  37. $this->resourceModel = $resourceModel;
  38. $this->studentsFactory = $studentsFactory;
  39.  
  40. parent::__construct($context);
  41. }
  42. /**
  43. * Save action
  44. *
  45. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  46. * @return MagentoFrameworkControllerResultInterface
  47. */
  48. public function execute()
  49. {
  50. $data = $this->getRequest()->getPostValue();
  51.  
  52. /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
  53. $resultRedirect = $this->resultRedirectFactory->create();
  54. //
  55. if ($data) {
  56. try{
  57. /** @var FuduHelloWorldModelStudents $model */
  58.  
  59. $model = $this->studentsFactory->create();
  60.  
  61. $model->setData($data);
  62.  
  63. $this->resourceModel->save($model);
  64.  
  65. $this->messageManager->addSuccessMessage(__('Create Student Successfully.'));
  66.  
  67. // Redirect to your form page (or anywhere you want...)
  68. $resultRedirect->setPath('/companymodule/index/booking');
  69.  
  70. return $resultRedirect;
  71. }
  72. catch (Exception $e) {
  73. $this->messageManager->addErrorMessage($e->getMessage());
  74. }
  75.  
  76. }
  77. }
  78. }
Add Comment
Please, Sign In to add comment