What will be the return type of the execute method?

Your module adds a new controller class which will return a JSON response.
What will be the return type of the execute method?
A. You should implement a new API endpoint instead of returning JSON from a controller
B. The string value of Zend_Json::encode()
C. An instance of MagentoFrameworkControllerResultJson
D. No return needed, an object that can be converted to JSON must be set as the Response body

Download Printable PDF. VALID exam to help you PASS.

2 thoughts on “What will be the return type of the execute method?

  1. Answer: C

    Allowed return types and their classes

    /**#@-*/
    protected $typeMap = [
    self::TYPE_JSON => \Magento\Framework\Controller\Result\Json::class,
    self::TYPE_RAW => \Magento\Framework\Controller\Result\Raw::class,
    self::TYPE_REDIRECT => \Magento\Framework\Controller\Result\Redirect::class,
    self::TYPE_FORWARD => \Magento\Framework\Controller\Result\Forward::class,
    self::TYPE_LAYOUT => \Magento\Framework\View\Result\Layout::class,
    self::TYPE_PAGE => \Magento\Framework\View\Result\Page::class,
    ];

    from \Magento\Framework\Controller\ResultFactory

  2. Answer:- C

    return types
    A “MagentoFrameworkControllerResultJson” result
    A “MagentoFrameworkControllerResultRaw” result
    A “MagentoFrameworkControllerResultForward” result
    A “MagentoFrameworkControllerResultRedirect” result

    1. from \Magento\Framework\Controller\ResultFactory

      /**#@+
      * Allowed result types
      */
      const TYPE_JSON = ‘json’;
      const TYPE_RAW = ‘raw’;
      const TYPE_REDIRECT = ‘redirect’;
      const TYPE_FORWARD = ‘forward’;
      const TYPE_LAYOUT = ‘layout’;
      const TYPE_PAGE = ‘page’;

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.