Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VendorModuleControllerIndex;
- class Index extends MagentoFrameworkAppActionAction
- {
- protected $resultPageFactory;
- public function __construct(
- MagentoFrameworkAppActionContext $context,
- MagentoFrameworkViewResultPageFactory $resultPageFactory)
- {
- $this->resultPageFactory = $resultPageFactory;
- parent::__construct($context);
- }
- public function execute()
- {
- }
- }
- use MagentoFrameworkAppActionAction;
- use MagentoFrameworkAppActionContext;
- use MagentoFrameworkAppResponseInterface;
- class Test extends Action
- {
- /**
- * @var MagentoFrameworkControllerResultJsonFactory
- */
- protected $resultJsonFactory;
- public function __construct(
- Context $context,
- MagentoFrameworkControllerResultJsonFactory $resultJsonFactory
- ) {
- parent::__construct($context);
- $this->resultJsonFactory = $resultJsonFactory;
- }
- /**
- * Dispatch request
- *
- * @return MagentoFrameworkControllerResultInterface|ResponseInterface
- * @throws MagentoFrameworkExceptionNotFoundException
- */
- public function execute()
- {
- /** @var MagentoFrameworkControllerResultJson $result */
- $result = $this->resultJsonFactory->create();
- $resultData = [
- 'any_key' => 'Any data goes here',
- 'success' => true,
- 'time' => time(),
- 'replace_button_message' => __('Your store has been already registered'),
- ];
- return $result->setData($resultData);
- }
- }
- <?php
- namespace VendorControllerControllerIndex;
- use MagentoFrameworkAppActionAction;
- class Index extends Action
- {
- public function execute()
- {
- $jsonResult = ['data' => 'test'];
- $this->getResponse()->representJson(
- $this->_objectManager->get(MagentoFrameworkJsonHelperData::class)->jsonEncode($jsonResult)
- );
- }
- }
- $this->getResponse()->representJson($this->_objectManger->get(Your Path::class)->JsonEncode($jsonResult));
Add Comment
Please, Sign In to add comment