Since you have done a complete plugin that runs on the front office, today i'm gonna show what is in the back office. For example, your address book appears in the front end, how to ensure that your form appears in the back office. Yes, I will show how to create a plugin in your Magento backend office.
Before starting on the code, let’s start by understanding how the administration of magento works. First of all you have to know that in the admin plugin it is always the same, there will be a « code » part and a « template » part (the principle of MVC … separate the code and the view), the part code is found in the « code » folders of your plugin in a directory called Adminhtml.

Then, administration blocks of your plugin will be found in /app/code/local/Pfay/Test/Block/Adminhtml/
The controllers will be found in /app/code/local/Pfay/Test/controllers/Adminhtml/
And model is the same for the admin and the front part, of course we will not create a new one when it already existing.
For the backoffice part, you’ll search your templates and your layout in /app/design/adminhtml/default/Pfay/, once you are here. It’s the same as for the front, you have your file layout and your folder template where you store your layout and your respective templates.
1. Edit the Config.xml file in our plugin
Obviously you are used, let's start by editing the config.xml file in our plugin, go to /app/code/local/Pfay/Test/etc/.
After <\frontend> and before <global> add:
<admin>
<routers>
<test>
<use>admin</use>
<args>
<module>Pfay_Test</module>
<frontName>admintest</frontName>
</args>
</test>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<test>
<file>test.xml</file>
</test>
</updates>
</layout>
<menu>
<test translate="title" module="adminhtml">
<title>My plugins</title>
<sort_order>100</sort_order>
<children>
<set_time>
<title>Adress book</title>
<action>admintest/adminhtml_index</action>
</set_time>
</children>
</test>
</menu>
</adminhtml>
The changes will show below:
<admin>
<routers>
<test>
<use>admin</use>
<args>
<module>Pfay_Test</module>
<frontName>admintest</frontName>
</args>
</test>
</routers>
</admin>
Then, you can create an administration router, the tag is set to use the admin can say that it will be an administration plugin (as opposed to if we had used the standard value).
To access to the admin part of our plugin, we define a shortcut to the url thanks to the attribute frontName that we make as « admintest ». To access our plugin we will therefore go to the URL: votresite.com/admintest/adminhtml_index
<adminhtml>
<layout>
<updates>
<test>
<file>test.xml</file>
</test>
</updates>
</layout>
<menu>
<test translate="title" module="adminhtml">
<title>My plugins</title>
<sort_order>100</sort_order>
<children>
<set_time>
<title>Adress book</title>
<action>admintest/adminhtml_index</action>
</set_time>
</children>
</test>
</menu>
</adminhtml>
Let's define that the layout used to load this plugin will be file test.xml who will be in the folder /app/design/adminhtml/default/Pfay/ layout/
Thanks to the the tag menu we’re creating the menu for the administration. The tag is easy to decode, it says:
Title: the title of the column (here « My plugins »)
set_order: the order in the menu (here 100 to put it at the end)
Then each children of this tag is a line of the menu. For each item children, there is a name and a link … In fact, each children menu is just a shortcut, if you will click on it, you are redirected to the page (in our example to yoursite.com/admintest/adminhtml_index )
2. Create the controller of the admin part
Create the folder \app\code\local\Pfay\Test\controllers\Adminhtml\ and the file IndexController.php in it which will contain:
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
3. Add the form in the admin interface
Now your plugin works and can be accessed via the menu, even if (for now) it does nothing.
To save time, copy your file that contains your form phtml to the admin of magento, take the file afficher.phtml located in /app/design/frontend/pfay/theme/template/test/ and copy it to /app/design/ adminhtml /default/ Pfay /template/test/
In your form and add the following hidden field (required for security in magento):
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
Now, change the layout test.xml in /app/design/adminhtml/default/Pfay/layout/ like this:
<?xml version="1.0" ?>
<layout version="0.1.0">
<test_adminhtml_index_index>
<reference name="content">
<block type="test/monblock" name="afficher_monbloc"
template="test/afficher.phtml" />
</reference>
</test_adminhtml_index_index>
</layout>
As you have copied the template in your template admin directory, it combines the block from the front with your template admin and it works, you now have your form in the administration!
HostForLIFE.eu Magento Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.
