Set or Get request variables in Magento

Posted on September 15, 2010 with 6 Comments

Get Request params like this:

$productId = Mage::app()->getRequest()->getParam('product_id', 44);

Get every post variable in array like this:

$postData = Mage::app()->getRequest()->getPost();
// You can access individual variables like...
if (isset($postData['product_id'])) {
  echo $postData['product_id'];

Tags: , ,

Category: Magento

Comments (6)


  1. Nicolas says:

    Is it safe to use Mage::app()->getRequest()->getParam(‘product_id’, 44);? Does Magento clean-up the variable (SQL Injection and stuff)?


  2. srinivas says:

    If you want set request parameter, you have to use setParam method instead getParam

    Mage::app()->getRequest()->getParam(‘product_id’, 44);


    Mage::app()->getRequest()->setParam(‘product_id’, 44);

  3. Farhan says:


    The use of $productId = Mage::app()->getRequest()->getParam(‘product_id’, 44); requires a little clarification.

    Can you confirm the second parameter “44″ will be return in case of no parameter or value is set to GET["product_id"] like the way its being managed in CodeIgniter?

    Farhan Islam

  4. nisha says:


  5. nisha says:

    What is 44 indicating?