Guest User

Untitled

a guest
Jan 24th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. namespace VendorModuleControllerIndex;
  4.  
  5. class Index extends MagentoFrameworkAppActionAction
  6. {
  7.  
  8. protected $resultPageFactory;
  9.  
  10. public function __construct(
  11. MagentoFrameworkAppActionContext $context,
  12. MagentoFrameworkViewResultPageFactory $resultPageFactory)
  13. {
  14. $this->resultPageFactory = $resultPageFactory;
  15. parent::__construct($context);
  16. }
  17.  
  18. public function execute()
  19. {
  20.  
  21. }
  22. }
  23.  
  24. use MagentoFrameworkAppActionAction;
  25. use MagentoFrameworkAppActionContext;
  26. use MagentoFrameworkAppResponseInterface;
  27.  
  28. class Test extends Action
  29. {
  30.  
  31. /**
  32. * @var MagentoFrameworkControllerResultJsonFactory
  33. */
  34. protected $resultJsonFactory;
  35.  
  36. public function __construct(
  37. Context $context,
  38. MagentoFrameworkControllerResultJsonFactory $resultJsonFactory
  39. ) {
  40. parent::__construct($context);
  41. $this->resultJsonFactory = $resultJsonFactory;
  42. }
  43.  
  44. /**
  45. * Dispatch request
  46. *
  47. * @return MagentoFrameworkControllerResultInterface|ResponseInterface
  48. * @throws MagentoFrameworkExceptionNotFoundException
  49. */
  50. public function execute()
  51. {
  52. /** @var MagentoFrameworkControllerResultJson $result */
  53. $result = $this->resultJsonFactory->create();
  54. $resultData = [
  55. 'any_key' => 'Any data goes here',
  56. 'success' => true,
  57. 'time' => time(),
  58. 'replace_button_message' => __('Your store has been already registered'),
  59. ];
  60.  
  61. return $result->setData($resultData);
  62. }
  63. }
  64.  
  65. <?php
  66.  
  67. namespace VendorControllerControllerIndex;
  68.  
  69. use MagentoFrameworkAppActionAction;
  70.  
  71. class Index extends Action
  72. {
  73. public function execute()
  74. {
  75. $jsonResult = ['data' => 'test'];
  76.  
  77. $this->getResponse()->representJson(
  78. $this->_objectManager->get(MagentoFrameworkJsonHelperData::class)->jsonEncode($jsonResult)
  79. );
  80. }
  81. }
  82.  
  83. $this->getResponse()->representJson($this->_objectManger->get(Your Path::class)->JsonEncode($jsonResult));
Add Comment
Please, Sign In to add comment