0

I don't understand getResponse and getRequest functions of the Mage_Core_Controller_Varien_Action class.

EDIT:

See below an explanation of getUrl function!

Thanks!

2

getRequest() & getResponse() are basic functions that returns the Request & Response models for the current instance of page load.

More Clarification on getRequest() - Basically whenever you invoke a page via Controllers Action, you may pass some data as a Request(eg: Form data to save, Record Id to fetch information etc). This is nothing but request params to server for performing certain action. These all requested information goes within a Request Model. In controller action you can get these params as

$this->getRequest()->getParam();

More Clarification on getResponse() - Basically whenever you invoke a page via Controllers Action, you may expect some sort of response(eg: HTML content of page, JSON response format etc). This is nothing but response from server on calling a action. These all response information goes within a Response Model. In controller action you can set/update response as

$this->getResponse()->setHeader('Content-Type', 'application/json', true)->setBody(json_encode($result));

Add-On Bonus Knowledge: ;)

More Clarification on getUrl() - Mage::getUrl() returns the Base Url of the website. You can pass params to get specific Url for any module, controller & action. Eg: You wanna get URL for Registration page, so you will call as Mage::getUrl("customer/account/create"). This will return full Url to Registration page. Pattern is <module>/<controller>/<action>.

You can pass * in case you wanna use current entity like module,controller or action. * will get replaced with current path. Eg: Consider you are now in customer/account/login action. Following will be output for getUrl() from this action.

Mage::getUrl()             -- <Base_Url>
Mage::getUrl("*")          -- <Base_Url>/customer/
Mage::getUrl("*/*")        -- <Base_Url>/customer/account/
Mage::getUrl("*/*/*")      -- <Base_Url>/customer/account/login/
Mage::getUrl("*/*/create") -- <Base_Url>/customer/account/create/

Hope it finds you helpful.

  • oh nice thanks ! I don't understand another function.. getUrl('*/*') what is the meaning of this parameter ?? – – Theo Cerutti Aug 14 at 11:08
  • @TheoCerutti I have updated my answer for getUrl(). Please go through it. – Abdul Pathan Aug 14 at 12:24
1

getRequest: this function used for get request parameter suppose if you are submitting a form and u want to get those submitted data then u have to use getRequest method for same.

getResponse : by using this function you redirect to any page etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.