I am using same controller for front-end and back-end action, everything works fine except setting global messages when redirect back to desired admin page.
I have used standard admin session handler to set messages for admin actions:
$notifierObject = Mage::getSingleton('adminhtml/session');
PS:
Controller being called is of front-end type.
Redirected admin page is an order view page.
Thanks in advance.
EDIT
Customer action : my.testdomain.com/modulename/controllerfrontname/action1 is called when form is submitted.
Similar form is there in admin sales order view page. Admin form submit action : my.testdomain.com/modulename/controllerfrontname/action1 , as you can see the same action is called.
frontName of admin and frontend routers is the same - modulename.(But I guess, this is not causing any problem)
I am successfully getting redirected back to admin sales order view page, but without any global messages that I have set in $notifierObject of admin session. That's the only problem.
-
As answers to this question suggests that this is not a proper way to avoid redundancy even though your logic part works perfectly.SOlearner– SOlearner2014年12月02日 14:28:34 +00:00Commented Dec 2, 2014 at 14:28
3 Answers 3
your question is somehow unclear, but I can give you one hint.
Don't use the same controller for frontend and backend.
you should have 2 of them because they serve 2 different purposes.
If you don't want to duplicate the code, out the common methods in a helper and call them in the different controllers.
-
Thank you for your prompt suggestion.. and yes, moving common piece of code to helper for both controllers to use it, seems perfect solution.SOlearner– SOlearner2014年12月02日 13:34:34 +00:00Commented Dec 2, 2014 at 13:34
In addition to Marius answer, sharing a controller between frontend and adminhtml is actually quite impossible.
For the controllers to work adminhtml needs to extend Mage_Adminhtml_Controller_Action while the frontend controller needs to extend Mage_Core_Controller_Front_Action.
Depending on what kind of code is shared between the two controllers it should either be moved to a Helper or a Model
If by your question you mean you are using the same frontName for both a frontend and backend router in your config.xml then you will get issues when routing requests - Magento won't neccessarily route to correct admin or frontend controller. A better setup is to use the existing admin router for your admin controller requests, and define a new router for frontend requests. Doing it this way also allows you to easily distinguish between an admin, and a frontend request. So in config.xml:
<?xml version="1.0"?>
<config>
...
<frontend>
...
<routers>
<module>
<use>standard</use>
<args>
<module>NameSpace_Module</module>
<frontName>module</frontName>
</args>
</module>
</routers>
...
</frontend>
...
<admin>
...
<routers>
<adminhtml>
<args>
<modules>
<NameSpace_Module before="Mage_Adminhtml">NameSpace_Module</NameSpace_Module>
</modules>
</args>
</adminhtml>
</routers>
...
</admin>
...
</config>