How to Pass Parameter to Controller in Magento

controllers

Is it possible in magento to send parameter to controller form?

    $x=987654;
    $url=Mage::helper("adminhtml")->getUrl("/label/setlabel");
    $block->addButton('label', array(
                     "label" => "Get Label",
                     "onclick" =>"popWin('$url', 'windowname', 'width=400,height=300,scrollbars=yes')
                                    )
    );"

controller file:

class MyCompany_MyModule_Adminhtml_LabelController
extends Mage_Adminhtml_Controller_Action
{
    public function setlabelAction()
        {
           echo $x;//is this possible?
        }
}

I have this $x parmeter, is it possible somehow to send it to controller and echo it there?

Best Answer

You can send that parameter through GET by making the url look like this:

$url=Mage::helper("adminhtml")->getUrl("/label/setlabel", array('param_name'=>$paramValue));

So in your case it can be

 $url=Mage::helper("adminhtml")->getUrl("/label/setlabel", array('x'=>$x));

Then you can read it in the controller like this:

$x = $this->getRequest()->getParam('x');