0

I am using Magento 1.9. Let's just say the documentation and community support is extremely lacking. I have spent the last week trying to figure out how to make a simple static HTML page for the admin area of Magento. Between incomplete tutorials and outdated documentation, it's a nightmare.

I BELIEVE I am at a point now where the admin page is actually loading, but it's blank so I can't tell. I guess now I am trying to figure out how to tell the system to use the layout for this page. (Again, it's going to be a static HTML page with a paragraph of text and an embedded YouTube video).

Let's get to the work here: This is my config.xml: - UPDATED

<config>
  <modules>
    <Cen_Tutorial>
      <version>0.1.0</version>
    </Cen_Tutorial>
  </modules>
  <global>
    <helpers>
      <cen_tutorial>
        <class>Cen_Tutorial_Helper</class>
      </cen_tutorial>
    </helpers>
  </global>
  <layout>
    <updates>
      <tutorial>
        <file>pdftutorial.xml</file>
      </tutorial>
    </updates>
  </layout>
  <admin>
    <routers>
      <adminhtml>
        <args>
          <modules>
            <Cen_Tutorial after="Mage_Adminhtml">Cen_Tutorial_Adminhtml</Cen_Tutorial>
          </modules>
        </args>
      </adminhtml>
    </routers>
  </admin>
</config>

And this is my adminhtml.xml: - UPDATED

<config>
  <menu>
    <cen translate="title" module="cen_tutorial">
      <title>PDF Tutorial</title>
      <sort_order>99</sort_order>
      <action>adminhtml/cen_tutorial/index</action>
    </cen>
  </menu>
</config>

This is my TutorialController.php: - UPDATED

Now in /app/code/community/Cen/Tutorial/controllers/Adminhtml/Cen/TutorialController.php:

<?php

class Cen_Tutorial_Adminhtml_Cen_TutorialController extends Mage_Adminhtml_Controller_Action
{
  public function indexAction()
  {
    $this->loadLayout();
    $this->renderLayout();
  }
}

This is the contents of my /app/design/adminhtml/default/default/layout/pdftutorial.xml:

<layout>
  <adminhtml_cen_tutorial_index>
    <update handle="adminhtml_cen_tutorial_index" />
    <reference name="content">
      <block type="adminhtml/template" name="tutorial" template="cen/index.phtml" />
    </reference>
  </adminhtml_cen_tutorial_index>
</layout>

And finally, the contents of my /app/design/adminhtml/default/default/template/cen/index.phtml:

<?php
  echo 'Hello, world!';
?>

This entire system and structure seems completely complicated, not well documented, and difficult to do anything with, even something as simple as creating one single use-page. What seems to be the problem with what I've pasted? I am on Magento 1.9.

I forgot to include my Helper class but it's in the source.

2
  • firstly you have error in your xml befor not after in this line <Cen_Tutorial after="Mage_Adminhtml">Cen_Tutorial</Cen_Tutorial> Commented Nov 22, 2017 at 20:33
  • and <layout> will be under <config><adminhtml> directly not <config><admin><adminhtml> Commented Nov 22, 2017 at 20:36

1 Answer 1

0

With few adjustments I was able to get your template to render:

Step1:

Let`s start with controller. Your definition is not up to the standards and this is how it should look:

 <admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Cen_Tutorial before="Mage_Adminhtml">Cen_Tutorial_Adminhtml</Cen_Tutorial>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

the difference is

  • since one of the patches we keep all our admin controller in folder controllers/Adminhtml thus the class path Cen_Tutorial_Adminhtml
  • Additionally you may want to consider moving your controllers in subfolder, i.e. Cen so that this one would become controllers/Adminhtml/Cen/TutorialController.php
  • That is because controller class/path relative to the module will set its url
  • i.e if you were to create ProductController.php for some reason - it will collide with core ProductController and something entirely unrelated will be broken
  • So it is better to use namespaces (folders with the name of vendor/module) for controllers

Step2:

Layout then. In global <config> there are several nodes that can be used. Some of them are:

  • admin
  • frontend
  • adminhtml
  • global (note that adminhtml will be in the same level global is)

in this case - because we want our template in admin area - we will want to use adminhtml node so the config becomes:

<config>
<modules>
    <Cen_Tutorial>
        <version>0.1.0</version>
    </Cen_Tutorial>
</modules>
<global>
    <helpers>
        <cen_tutorial>
            <class>Cen_Tutorial_Helper</class>
        </cen_tutorial>
    </helpers>
</global>
<adminhtml>
    <layout>
        <updates>
            <tutorial>
                <file>pdftutorial.xml</file>
            </tutorial>
        </updates>
    </layout>
</adminhtml>
<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Cen_Tutorial after="Mage_Adminhtml">Cen_Tutorial_Adminhtml</Cen_Tutorial>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
</config>

And we place our file in appropriate path, like app/design/adminhtml/default/default/layout/pdftutorial.xml

Step3:

Layout

In this particular case and naming we have - the layout is correct, but here are some things to note:

  • update handle does nothing, unless there is some tutorial_tutorial_index somehwere. If that's the case - you will inherit all its contents
  • layout handle adminhtml_tutorial_index is created from controller path. in this case (admin area) the first part is adminhtml, second part is full controller path (relative to the Adminhtml folder) and the 3 part is controller action
  • So if you were to move your controller into Adminhtml/Cen/TutorialController - layout handle would be: <adminhtml_cen_tutorial_index> and also all paths would become the same (i.e <action>adminhtml/cen_tutorial/index</action>)

So after applying some changes: enter image description here

Hope I was able to help and this made some sense.

12
  • I am trying to keep up with your comment, but I can't quite see what is different. In attempting to change config.xml it looks exactly like the one you pasted. Aside from moving the controller into controllers/Adminhtml/TutorialController.php, I don't see anything else that's different from what I have in my source.
    – Ex0r
    Commented Nov 22, 2017 at 20:39
  • Yours is inside <admin> node but mine is one level higher. Inside <config>. Will add whole config.xml in a minute.
    – austris
    Commented Nov 22, 2017 at 20:42
  • Hmm, now I am getting an error on the page when accessing it, except I have error display disabled so I cant see what it is. Controller file was loaded, but class does not exist
    – Ex0r
    Commented Nov 22, 2017 at 20:47
  • Okay, so then it is report. One checks what is written there with cat var/report/#number or copying errors/local.xml{.sample,}
    – austris
    Commented Nov 22, 2017 at 20:49
  • Yeah, the error is 'Controller file was loaded but class does not exist', This started after I moved TutorialController to /controllers/Adminhtml/Cen/TutorialController.php
    – Ex0r
    Commented Nov 22, 2017 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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