1

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

  • What is your Magento version ? – Prateek Feb 2 '16 at 7:04
  • Magento 1.8.1.0 – Patrick Knudsen Feb 2 '16 at 7:06
  • Have you installed SUPEE - 6788 ? It has changed the way adminhtml routers must be defined. – Prateek Feb 2 '16 at 7:07
  • No i have not. Should I do so? – Patrick Knudsen Feb 2 '16 at 7:10
  • From point of security, yeah you should, but that will require you to change a lot of modules including this one. You have different child names in menu and acl nodes in your config.xml file. Try making them identical, log out and then log back in. – Prateek Feb 2 '16 at 7:18
2

You'll need to provide more information. You're config.xml is completely wrong though. This should help get you started.

Config.xml:

<?xml version="1.0"?>
<config>
    <modules>
    <Puk_EmailOrder>
        <version>1.0.0</version>
    </Puk_EmailOrder>
    </modules>
    <adminhtml>
        <layout>
            <updates>
                <emailorder>emailorder.xml</emailorder>
            </updates>
        </layout>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Puk_EmailOrder before="Mage_Adminhtml">Puk_EmailOrder_Adminhtml</Puk_EmailOrder>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

Your menu stuff should be in adminhtml.xml thats also wrong too:

<?xml version="1.0"?>
<config>
<menu>
    <awesome translate="title" module="puk_emailOrder">
        <title>Your Title</title>
        <sort_order>15</sort_order>
        <children>
            <example translate="title" module="puk_emailOrder">
                <title>Example</title>
                <sort_order>1</sort_order>
                <action>adminhtml/example/index</action>
            </example>
        </children>
    </awesome>
</menu>
</config>

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

  • ive just shortet down my config.xml :P Just added the whole thing. – Patrick Knudsen Feb 2 '16 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.