When you log into adminstrator part of the Magento webshop, and look into the url you may see something like this.
Admin URL with Keys and Parameters
The part in “RED” are module controller(router)/action. And the part in “GREEN” is what we call as “Paramerters” and the “BLUE” part is the “Key“. The Key (which is also a URL parameter) in the URL has been added for security reasons and is checked against the session’s values for every action. If store owner does not want to use the key in admin url, then it can be set off from administrator settings.
My point in this post is, if you are a developer and creating a module that has Admin controller and you are simply calling some action of your controller lets say, mymodule/adminhtml_mycontroller/myaction/param1/1/param2/2 the it does not redirect you to your intended page, but will redirect to dashboard, IF key is enabled. You will have to add the key parameter to the URL to go to your page. So here is a simple snippet of code that will help you to build your URL with valid keys.
echo Mage::helper("adminhtml")->getUrl("mymodule/adminhtml_mycontroller/myaction/",array("param1"=>1,"param2"=>2));
The “adminhtml” helper will automatically create url with keys attached to the URL.
Next thing, if you see the key of various pages in admin you will see that those keys are not same, there is a different logic behind creating those key values. The keys generated depends upon the controller and action you are about to execute. Keys can be seperatly generated as follows.
Mage::getSingleton('adminhtml/url')->getSecretKey("adminhtml_mycontroller","myaction");
Hope this helps, and this can be particularly helpful when you are using templates in admin modules and adding buttons to redirect to some other location. At least that was my case!
Thanks a lot!
thanks for pointing this issue for customizing admin area in magento
regards,
Riki Risnandar
Thanks! I was using Mage::getUrl() and the key param was missing.
Thanks brother.I understand Magento admin in a better way now
Hi all!
First of all, very useful tip, thanks Subesh
Your key solution works only for the same admin user.
Scenario:
- admin ‘A’ creates an url with function above;
- admin ‘A’ correctly navigate this url;
- any other admin can’t.
Is there a solution for this?
I think it will not matter who ever navigates.
Think you!
This really very very useful!
Hi, All
I have displayed the customer list block in admin custom module.Can any body tell me how to get ids of two customer, say oncheck of the checkboxes or i have also created radio button column ,so on change in that case?
Much obliged, it helped me out.
very helpful. thanks for sharing!
Well, when you are developing a new module and you go on some controller by firing some action then at that time you do not get index/key/blah….blah..
part.Really useful….
Great!!!
Thank for the information.
You are my saver.