Admin controller not working in Magento - 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

Related

Magento 1.9 add layout and template to custom module in admin

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>.

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>

override orders controller in magento

I have a custom module Permissions_Orders. Here is my code to override orders controller from base admin -
config.xml -
<admin>
<routers>
<adminhtml>
<args>
<modules>
<orders before="Mage_Adminhtml">Orders_Adminhtml_Sales_OrderController</orders>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Permissions/Orders/controllers/Adminhtml/Sales/OrderController.php -
<?php
require_once 'Mage/Adminhtml/controllers/Sales/OrderController.php';
class Permissions_Orders_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
----
}
but still it is calling from base controller. I am not sure, where I am wrong here. Any help is appreciated.
Your config.xml should look like below,
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<orders before="Mage_Adminhtml">Permissions_Orders_Adminhtml</orders>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Notice the change in </orders> node.
In config.xml is enough to specify the namespace and module name where you want to extend the base adminhtml controllers.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Namespace_Adminhtml before="Mage_Adminhtml">Namespace_Adminhtml</Namespace_Adminhtml>
</modules>
</args>
</adminhtml>
</routers>
</admin>

config.xml front name not working while entering front name in url

I have created my custom module that is working fine at backend(Add,Edit,Delete,List) but while I enter frontname in url it shows me page not found error. below is my code
<frontend>
<routers>
<ydg_cylinderworksheet>
<use>standard</use>
<args>
<module>ydg_Cylinderworksheet</module>
<frontName>cylinder-worksheet</frontName>
</args>
</ydg_cylinderworksheet>
</routers>
<layout>
<updates>
<ydg_cylinderworksheet>
<file>ydg_cylinderworksheet.xml</file>
</ydg_cylinderworksheet>
</updates>
</layout>
<translate>
<modules>
<ydg_Cylinderworksheet>
<files>
<default>ydg_Cylinderworksheet.csv</default>
</files>
</ydg_Cylinderworksheet>
</modules>
</translate>
</frontend>
You needd to change your routers tag in your etc/config.xml
<routers>
<cylinderworksheet>
<use>standard</use>
<args>
<module>Ydg_Cylinderworksheet</module>
<frontName>cylinder-worksheet</frontName>
</args>
</cylinderworksheet>
</routers>
....
You need to change your code
<frontend>
<routers>
<cylinderworksheet>
<use>standard</use>
<args>
<module>ydg_Cylinderworksheet</module>
<frontName>cylinderworksheet</frontName>
</args>
</cylinderworksheet>
</routers>
.........

Magento getURL not finding controller of custom module

I am adding in a new mass action for the sales order grid and when I am putting in the url for my action Magento cannot find my controller.
config.xml
<admin>
<routers>
<mymodule>
<use>admin</use>
<args>
<module>Namespace_mymodule</module>
<frontName>frontendname</frontName>
</args>
</mymodule>
</routers>
</admin>
<global>
<events>
<adminhtml_block_html_before>
<observers>
<mymodule>
<class>Namespace_mymodule_Model_Observer</class>
<method>addActions</method>
</mymodule>
</observers>
</adminhtml_block_html_before>
</events>
</global>
observer.php
public function addActions($event)
{
$block = $event->getBlock();
if($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)
{
$block->getMassactionBlock()->addItem('cpsync', array(
'label' => 'Push Orders to CounterPoint',
'url' => Mage::helper("adminhtml")->getUrl("frontendname/adminhtml_index/push/")
));
}
}
Whenever I try to use my mass action it sends me to a 404 redirect page with url
sitename.com/index.php/frontendname/adminhtml_index/push/key/
I think your config.xml is wrong. In the above config.xml, you havent mentioned about the model, block or helper classes. You had just declared about the module and an event. Here is the basic config.xml that you have to follow. Try to modify your config.xml as below.
<?xml version="1.0"?>
<config>
<modules>
<Test_Helloworld>
<version>0.1.0</version>
</Test_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Test_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
</frontend>
<global>
<blocks>
<helloworld>
<class>Test_Helloworld_Block</class>
</helloworld>
</blocks>
<helpers>
<helloworld>
<class>Test_Helloworld_Helper</class>
</helloworld>
</helpers>
</global>
</config>

Resources