Magento 1.9 add layout and template to custom module in admin - magento

I try to create custom module that shows on main page two tabs with option to change titles, backgrounds, colors.
I successfully add the module tab in admin and can't add layout and template.
I'm stuck.
Can any one explain, please, how I can do this?
Here are the xml files that I got:
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Lern_Sample>
<version>0.1.0</version>
</Lern_Sample>
</modules>
<frontend>
<routers>
<sample>
<use>standard</use>
<args>
<module>Lern_Sample</module>
<frontName>sample</frontName>
</args>
</sample>
</routers>
</frontend>
<admin>
<routers>
<sample>
<use>admin</use>
<args>
<module>Lern_Sample</module>
<frontName>admin_sample</frontName>
</args>
</sample>
</routers>
</admin>
<global>
<helpers>
<sample>
<class>Lern_Sample_Helper</class>
</sample>
</helpers>
</global>
<adminhtml>
<menu>
<sample module="sample">
<title>Sample Module</title>
<sort_order>100</sort_order>
<children>
<sample module="sample">
<title>Sample Module</title>
<sort_order>0</sort_order>
<action>admin_sample/adminhtml_index</action>
<layout>
<lern_sample>
<file>lern_sample.xml</file>
</lern_sample>
</layout>
</sample>
</children>
</sample>
</menu>
</adminhtml>
module xml etc/Lern_Sample.xml
<?xml version="1.0"?>
<config>
<modules>
<Lern_Sample>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Adminhtml />
</depends>
</Lern_Sample>
</modules>

You can add your own layout file by declaring it under the node <frontend>, just like this :
<layout>
<updates>
<sample>
<file>sample.xml</file>
</sample>
</updates>
</layout>
Your layout file will have to be located under app/design/frontend/MY_CUSTOM_PACKAGE/MY_DEFAULT_THEME/layout/sample.xml or under the base installation app/design/frontend/base/default/layout/sample.xml
If you try to add a layout update file for the admin, just use this code sample under the node <adminhtml>.

Related

I am Having issues when adding menu in admin panel magento

I 've made a file to add my module as: [ File as- Axovel_MenuItem.xml]
<?xml version="1.0"?>
<config>
<modules>
<Axovel_MenuItem>
<active>true</active>
<codePool>local</codePool>
</Axovel_MenuItem>
</modules>
</config>
in folder app/etc/modules/
then i made a configuration file(config.xml) as
<?xml version="1.0"?>
<config>
<modules>
<Axovel_MenuItem>
<version>0.1.0</version>
</Axovel_MenuItem>
</modules>
<global>
<helpers>
<menuitem>
<class>Axovel_MenuItem_Helper</class>
</menuitem>
</helpers>
</global>
<frontend>
<routers>
<menuitem>
<routeurfrontend>
<use>standard</use>
<args>
<module>Axovel_MenuItem</module>
<frontName>menuitem</frontName>
</args>
</routeurfrontend>
</menuitem>
</routers>
</frontend>
<adminhtml>
<layout>
<updates>
<menuitem>
<file>menuitem.xml</file>
</menuitem>
</updates>
</layout>
<acl>
<resources>
<admin>
<children>
<menuitem>
<title>Awesome Menu Item</title>
<children>
<sub_menu1>
<title>Example Menu Item</title>
</sub_menu1>
</children>
</menuitem>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
in folder app/code/local/Axovel/MenuItem/etc/
then i made a Adminhtml Configuration File(adminhtml.xml) as
<?xml version="1.0"?>
<config>
<menu>
<menuitem>
<title>Awesome Menu Item</title>
<sort_order>20</sort_order>
<children>
<sub_menu1>
<title>Example Menu Item</title>
<sort_order>0</sort_order>
<!-- <action>menuitem/index/index</action> -->
</sub_menu1>
</children>
</menuitem>
</menu>
</config>
in folder app/code/local/Axovel/MenuItem/etc/
and made a Helper File(Data.php) as:
<?php
class Axovel_MenuItem_Helper_Data extends Mage_Core_Helper_Abstract
{
}
?>
in folder app/code/local/Axovel/MenuItem/Helper/
I also made a Controller file(IndexController.php) as:
<?php
class Axovel_MenuItem_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
?>
But Not Getting the Desired Results, I am not able to see my custom menu Item
Even i am not able to call my indexController/indexAction directly with Hyperlink as
http://127.0.0.1/magento/index.php/menuitem/index/index
there is something Wrong in config.xml but i am not able to figure it out, can anyone please Help?
Thanks :)
This looks like it is probably a caching issue. If you are new to magento, the cache can be easy to forget and really cause some problems for you. You should try clearing that in the backend or from the command line. cache is found in the var folder and you will want to empty bother the cache folder and the full_page_cache folder.
I don't know if the menu button will work or not because you didn't give any code that would generate a new page or block.

magento controller not found

I have set up a controller in my module to add an order export tab to my installation:
in config.xml:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<orderexport>abc_Orderexport_index2</orderexport>
</modules>
</args>
</adminhtml>
</routers>
<layout>
<updates>
<orderexport>
<file>orderexport.xml</file>
</orderexport>
</updates>
</layout>
</admin>
in adminhtml.xml:
<?xml version="1.0"?>
<config>
<menu>
<sales>
<children>
<orderexport>
<title>Order Export</title>
<sort_order>20</sort_order>
<action>adminhtml/index2</action>
</orderexport>
</children>
</sales>
</menu>
<acl>
<resources>
<admin>
<children>
<sales>
<children>
<orderexport>
<title>Order Export</title>
<sort_order>20</sort_order>
</orderexport>
</children>
</sales>
</children>
</admin>
</resources>
</acl>
</config>
and in the controllers/Adminhtml/Index2Controller.php file
class abc_Orderexport_Adminhtml_Index2Controller extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
However with all this done, whenever I click on the button "Order Export" it redirects me to the 404 page. That means that Magento cannot find the controller but idk why.
When i rename the controller everywhere from index2 into index (Index2Controller.php to IndexController.php) I am not getting redirected to the 404 page, HOWEVER the Dashboard of the admin panel just reloads.
I really don't know where my error is and Im happy for any hints into the right direction.
Here is what you have to fix:
in config.xml: you have to say that your module should be use in the adminhtml area, and you have to respect the CamelCase, here is how it should look like:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Abc_Orderexport after="Mage_Adminhtml">Abc_Orderexport_Adminhtml</Abc_Orderexport>
</modules>
</args>
</adminhtml>
</routers>
</admin>
in your controller, again, you must respect CamelCase, i.e. the class name is Abc_Orderexport_Adminhtml_Index2Controller
All this is assuming your folder structure is:
app/
code/
local/
Abc/
Orderexport/
controllers/
Adminhtml/
Index2Controller.php
etc/
config.xml
adminhtml.xml
, exactly, upper/lower case is important
Could you please try the following code and make sure that you module class name and folder structure must be in standard magento
extension structure. config.xml
<admin>
<routers>
<orderexport>
<use>admin</use>
<args>
<modules>
<orderexport>Abc_Orderexport_Index2</orderexport>
<frontName>orderexport</frontName>
</modules>
</args>
<orderexport>
</routers>
<layout>
<updates>
<orderexport>
<file>orderexport.xml</file>
</orderexport>
</updates>
</layout>
</admin>

Magento not able to assign Rewrite Reports Product Viewed block

I just need to create recent Product View Slider.
So i want to overide Reports_Product_Viewed block from core file.
I wrote config.xml for this but on product page I ma not able to do this.
Basically I want to overide Reports product block and want to append some code in that for the recent product slider.
my config.xml is
----------------
<?xml version="1.0"?>
<config>
<modules>
<Deepak_Recent>
<version>0.1.0</version>
</Deepak_Recent>
</modules>
<global>
<blocks>
<recent>
<rewrite>
<reports_product_viewed>Deepak_Recent_Block_Product_Viewed</reports_product_viewed>
</recent>
</catalog>
</blocks>
<helpers>
<recent>
<class>Deepak_Recent_Helper</class>
</recent>
</helpers>
</global>
<frontend>
<routers>
<recent>
<use>standard</use>
<args>
<module>Deepak_Recent</module>
<frontName>recent</frontName>
</args>
</recent>
</routers>
<layout>
<updates>
<recent>
<file>recent.xml</file>
</recent>
</updates>
</layout>
</frontend>
</config>
my rewrite block
-----------------
<?php
class Deepak_Recent_Block_Product_Viewed extends Mage_Reports_Block_Product_Viewed{
public function getme(){ echo 'block loaded';}
}
my layout.xml
---------------
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_product_view>
<reference name="product.info">
<block type="recent/product" name="product.info.recent" template="carousel/products_recent_horizontal.phtml"/>
</reference>
</catalog_product_view>
</layout>
and alst my phtml file
-----------------
<?php
echo $this->getme();exit;
?>
your config.xml file should be
<config>
<modules>
<Deepak_Recent>
<version>0.1.0</version>
</Deepak_Recent>
</modules>
<global>
<blocks>
<reports> <!-- Changes here start -->
<rewrite>
<product_viewed>Deepak_Recent_Block_Product_Viewed</product_viewed>
</rewrite>
</reports> <!-- Changes here end -->
</blocks>
<helpers>
<recent>
<class>Deepak_Recent_Helper</class>
</recent>
</helpers>
</global>
<frontend>
<routers>
<recent>
<use>standard</use>
<args>
<module>Deepak_Recent</module>
<frontName>recent</frontName>
</args>
</recent>
</routers>
<layout>
<updates>
<recent>
<file>recent.xml</file>
</recent>
</updates>
</layout>
</frontend>
</config>
Actually issue was in
<blocks>
<reports> <!-- Changes here start -->
<rewrite>
<product_viewed>Deepak_Recent_Block_Product_Viewed</product_viewed>
</rewrite>
</reports> <!-- Changes here end -->
</blocks>

Admin controller not working in Magento

I've used a yeoman generator to build a Magento Module skeleton.
I can access the frontend module simply with:
http://prueba.com/index.php/prueba/index
But I can't make it work the admin. These are my files:
/etc/adminhtml.xml
<config>
<menu>
<prueba>
<title>My Tab</title>
<sort_order>1</sort_order>
<action>adminhtml/prueba/index</action>
</prueba>
</menu>
</config>
/controllers/adminhtml/IndexController.php
<?php
/**
* Index Adminhtml Controller
*
*/
class Altimea_Prueba_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
/**
* Index Action
*/
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
echo 'hello';
}
}
/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Altimea_Prueba>
<version>0.1.0</version>
</Altimea_Prueba>
</modules>
<global>
<models>
<altimeaprueba>
<class>Altimea_Prueba_Model</class>
</altimeaprueba>
</models>
<blocks>
<altimeaprueba>
<class>Altimea_Prueba_Block</class>
</altimeaprueba>
</blocks>
<helpers>
<altimeaprueba>
<class>Altimea_Prueba_Helper</class>
</altimeaprueba>
</helpers>
<resources>
<altimeaprueba_setup>
<setup>
<module>Altimea_Prueba</module>
<class>Altimea_Prueba_Model_Resource_Setup</class>
</setup>
</altimeaprueba_setup>
</resources>
</global>
<frontend>
<layout>
<updates>
<altimeaprueba>
<file>altimeaprueba.xml</file>
</altimeaprueba>
</updates>
</layout>
<routers>
<altimeaprueba>
<use>standard</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</frontend>
<adminhtml>
<layout>
<updates>
<altimeaprueba>
<file>altimeaprueba.xml</file>
</altimeaprueba>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<altimeaprueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</admin>
</config>
When create a magento admin module you can create it in one of two ways. Since you have both a front and backend controller try changing your admin route to <frontname>admin_prueba</frontname> then try http://prueba.com/index.php/admin_prueba/index
<adminhtml>
<menu>
<menu1 translate="title" module="customlist">
<title>ActiveCodeline SampleModule1</title>
<sort_order>60</sort_order>
<children>
<menuitem1 module="SampleModule1">
<title>Menu item 1</title>
<action>{{customlist}}/index</action>
</menuitem1>
<admin>
<routers>
<samplemodule1>
<use>admin</use>
<args>
<module>ActiveCodeline_SampleModule1</module>
<frontname>admin_customlist</frontname>
</args>
</samplemodule1>
</routers>
</admin>
or
<adminhtml>
<menu>
<menu1 translate="title" module="customlist">
<title>ActiveCodeline SampleModule1</title>
<sort_order>60</sort_order>
<children>
<menuitem1 module="SampleModule1">
<title>Menu item 1</title>
<action>{{adminhtml/customlist}}/index</action>
</menuitem1>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Company_CustomList before="Mage_Adminhtml">Foo_Bar_Adminhtml</Company_CustomList>
</modules>
</args>
</adminhtml>
</routers>
</admin>
You have missed to add this in config.xml
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<altimea_prueba after="Mage_Adminhtml">Altimea_Prueba_Adminhtml</altimea_prueba>
</modules>
</args>
</adminhtml>
</routers>
</admin>
In config.xml, change this:
<admin>
<routers>
<altimeaprueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimeaprueba>
</routers>
</admin>
To this:
<admin>
<routers>
<altimea_prueba>
<use>admin</use>
<args>
<module>Altimea_Prueba</module>
<frontName>prueba</frontName>
</args>
</altimea_prueba>
</routers>
</admin>
If you want to see your "hello" printed out, in IndexController.php, add exit(); after your echo "hello";
Just a reference
It took me ages to figure out that
<args>
<modules>
<myrandomtag before="Mage_Adminhtml">
My_Module_Adminhtml
</myrandomtag>
</modules>
</args>
IS NOT SAME AS
<args>
<modules>
<myrandomtag before="Mage_Adminhtml">My_Module_Adminhtml</myrandomtag>
</modules>
</args>
So there should be no space or new line inside your random tag

Magento admin menu link stopped working after upgrade

Before upgradation to EE v1.12.0.2, we were running v1.10.1.1, at which point this code works fine to add an external link to the menu.
<?xml version="1.0"?>
<config>
<modules>
<Clean_Integration>
<version>1.0.0</version>
</Clean_Integration>
</modules>
<global>
<models>
<customer>
<rewrite>
<customer_api>Clean_Integration_Model_Customer_Customer_Api</customer_api>
</rewrite>
</customer>
</models>
<helpers>
<coaching>
<class>Clean_Integration_Helper</class>
</coaching>
</helpers>
</global>
<frontend>
<layout>
<updates>
<Clean_Integration module="Clean_Integration">
<file>cleanintegration.xml</file>
</Clean_Integration>
</updates>
</layout>
</frontend>
<adminhtml>
<menu>
<coaching translate="title" module="Integration">
<title>Coaching</title>
<sort_order>71</sort_order>
<url>/appointments/sync/backend/</url>
</coaching>
</menu>
<acl>
<resources>
<admin>
<children>
<coaching translate="title">
<title>Coaching</title>
</coaching>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
We had a link like domain.com/appointments/sync/backend/ with this but now with upgrade the menu entry appears but its not a link anymore. So, I am guessing something was changed in Magento which breaks this, any ideas?
<?xml version="1.0"?>
<config>
<modules>
<Clean_Integration>
<version>1.0.0</version>
</Clean_Integration>
</modules>
<global>
<models>
<customer>
<rewrite>
<customer_api>Clean_Integration_Model_Customer_Customer_Api</customer_api>
</rewrite>
</customer>
</models>
<helpers>
<integration>
<class>Clean_Integration_Helper</class>
</integration>
</helpers>
</global>
<frontend>
<layout>
<updates>
<integration>
<file>cleanintegration.xml</file>
</integration>
</updates>
</layout>
</frontend>
<adminhtml>
<menu>
<integration translate="title" module="integration">
<title>Coaching</title>
<sort_order>71</sort_order>
<action>appointments/sync/backend/</action>
</integration>
</menu>
<acl>
<resources>
<admin>
<children>
<integration translate="title">
<title>Coaching</title>
</integration>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
Create in /app/code/local/Clean/Integration/Helper/Data.php
<?php
class Clean_Integration_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Take a look # Create a sample admin module for form processing

Resources