I've got a block and I want to display something from my custom database backend but I get 404 error.
Here is the code
Config.xml
<?xml version="1.0"?>
<config>
<modules>
<Puk_EmailOrder>
<version>0.1.0</version>
</Puk_EmailOrder>
</modules>
<frontend>
<routers>
<routeurfrontend>
<use>standard</use>
<args>
<module>Puk_EmailOrder</module>
<frontName>emailorder</frontName>
</args>
</routeurfrontend>
</routers>
<layout>
<updates>
<emailorder>
<file>emailorder.xml</file>
</emailorder>
</updates>
</layout>
</frontend>
<global>
<helpers>
<emailorder>
<class>Puk_EmailOrder_Helper</class>
</emailorder>
</helpers>
<blocks>
<emailorder>
<class>Puk_EmailOrder_Block</class>
</emailorder>
</blocks>
<models>
<emailorder>
<class>Puk_EmailOrder_Model</class>
<resourceModel>emailorder_mysql4</resourceModel>
</emailorder>
<emailorder_mysql4>
<class>Puk_EmailOrder_Model_Mysql4</class>
<entities>
<emailorder>
<table>emailorder</table>
</emailorder>
</entities>
</emailorder_mysql4>
</models>
<resources>
<emailorder_setup>
<setup>
<module>Puk_EmailOrder</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</emailorder_setup>
<emailorder_write>
<connection>
<use>core_write</use>
</connection>
</emailorder_write>
<emailorder_read>
<connection>
<use>core_read</use>
</connection>
</emailorder_read>
</resources>
</global>
<admin>
<routers>
<emailorder>
<use>admin</use>
<args>
<module>Puk_EmailOrder</module>
<frontName>adminemailorder</frontName>
</args>
</emailorder>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<emailorder>
<file>emailorder.xml</file>
</emailorder>
</updates>
</layout>
<menu>
<emailorder translate="title" module="emailorder">
<title>Email Ordre</title>
<sort_order>100</sort_order>
<children>
<emailorderbackend>
<title>Email Orders</title>
<sort_order>0</sort_order>
<action>adminemailorder/adminhtml_index</action>
</emailorderbackend>
</children>
</emailorder>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<emailorder translate="title" module="emailorder">
<title>Email Order</title>
<sort_order>1000</sort_order>
<children>
<emailorderbackend translate="title">
<title>Email Orders</title>
</emailorderbackend>
</children>
</emailorder>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
Controller
(app/code/local/Puk/EmailOrder/controllers/Adminhtml/IndexController.php)
<?php
class Puk_EmailOrder_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Block.xml(app/code/local/Puk/EmailOrder/Block/Monblock.php)
<?php
class Puk_EmailOrder_Block_Monblock extends Mage_Core_Block_Template
{
public function methodblock()
{
//on initialize la variable
$retour='';
/* we are doing the query to select all elements of the pfay_test table (thanks to our model test/test and we sort them by id_pfay_test */
$collection = Mage::getModel('emailorder/emailorder')->getCollection()
->setOrder('emailorder_id','asc');
/* then, we check the result of the query and with the function getData() */
foreach($collection as $data)
{
$retour .= $data->getData('product_name').' '.$data->getData('location')
.' '.$data->getData('date_for').'<br />';
}
//i return a success message to the user thanks to the Session.
Mage::getSingleton('adminhtml/session')->addSuccess('YES!!');
return $retour;
}
}
Hope someone can help
Best Answer
You'll need to provide more information. You're config.xml is completely wrong though. This should help get you started.
Config.xml:
Your menu stuff should be in
adminhtml.xml
thats also wrong too:You will need to provide us your layout XML, you can create the block in the controller but you shouldn't do this IMO.
You will also get an error when you add your
adminhtml
because you need to add a helper for translations. I recommend following a tutorial online to be honest.This one looks okay, although as mentioned I'd move the block creation to layout xml.
http://www.greenacorn-websolutions.com/magento/building-a-magento-admin-module.php