Magento2 Controller Response Types (Page,Redirect,JSON,Forward,Raw)
Supports
- Magento 2.0.x, 2.1.x, 2.2.x, 2.3.x and 2.4.x
Required to run the following commands in Magento 2 root folder:
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
php bin/magento cache:clean
Install via zip
Responses Types :
-
Page : This returns HTML loaded from a layout handle.
Class : \Magento\Framework\View\Result\Page
Launch the below url.
Url : www.example.com/controllerresponsetypes/index/resultpage
Where www.example.com is your magento instance URL.
-
JSON : this returns a response in JSON format. It can be used in API or AJAX requests.
Class : \Magento\Framework\Controller\Result\Json
Launch the below url.
Url : www.example.com/controllerresponsetypes/index/resultjson
-
Raw : this returns whatever you want to be returned.
Class : \Magento\Framework\Controller\Result\Raw
Launch the below url.
Url : www.example.com/controllerresponsetypes/index/resultraw
-
Forward : this internally forwards to another controller without changing the URL.
Class : \Magento\Framework\Controller\Result\Forward
Launch the below url.
Url : www.example.com/controllerresponsetypes/index/resultforward
-
Redirect : this represents a 301 or 302 redirect. It is used when a user needs to be redirected to a different URL.
Class : \Magento\Framework\Controller\Result\Redirect
Lunch the below url.
Url : www.example.com/controllerresponsetypes/index/resultredirect