I am following the Magento for developers tutorial on the Magento Knowledge Base and after I reached part 4 (see the link), I’ve ran into a problem. I’ve done the changes specified in this part of the tutorial, and after that, with the “/helloworld/index/index” controller, the browser displays a completely empty output. The previously populated “goodbye” and “params” controllers seem fine as does the “showConfig” XML output.
Can anyone shed any light about it? Here are the differences to my previous checkpoint at the end of part 3:
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Configviewer/Model/Observer.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Configviewer/Model/Observer.php Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,32 @@
+<?php
+ class Magentotutorial_Configviewer_Model_Observer {
+ const FLAG_SHOW_CONFIG = 'showConfig';
+ const FLAG_SHOW_CONFIG_FORMAT = 'showConfigFormat';
+
+ private $request;
+
+ public function checkForConfigRequest($observer) {
+ $this->request = $observer->getEvent()->getData('front')->getRequest();
+ if($this->request->{self::FLAG_SHOW_CONFIG} === 'true'){
+ $this->setHeader();
+ $this->outputConfig();
+ }
+ }
+
+ private function setHeader() {
+ $format = isset($this->request->{self::FLAG_SHOW_CONFIG_FORMAT}) ?
+ $this->request->{self::FLAG_SHOW_CONFIG_FORMAT} : 'xml';
+ switch($format){
+ case 'text':
+ header("Content-Type: text/plain");
+ break;
+ default:
+ header("Content-Type: text/xml");
+ }
+ }
+
+ private function outputConfig() {
+ die(Mage::app()->getConfig()->getNode()->asXML());
+ }
+ }
+?>
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Configviewer/etc/config.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Configviewer/etc/config.xml Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,20 @@
+<config>
+ <modules>
+ <Magentotutorial_Configviewer>
+ <version>0.1.0</version>
+ </Magentotutorial_Configviewer>
+ </modules>
+ <global>
+ <events>
+ <controller_front_init_routers>
+ <observers>
+ <Magentotutorial_configviewer_model_observer>
+ <type>singleton</type>
+ <class>Magentotutorial_Configviewer_Model_Observer</class>
+ <method>checkForConfigRequest</method>
+ </Magentotutorial_configviewer_model_observer>
+ </observers>
+ </controller_front_init_routers>
+ </events>
+ </global>
+</config>
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,23 @@
+<?php
+class Magentotutorial_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {
+
+ public function indexAction() {
+
+ echo 'Hello Index!';
+
+ }
+
+ public function goodbyeAction() {
+ echo 'Goodbye World!';
+ }
+
+ public function paramsAction() {
+ echo '<dl>';
+ foreach($this->getRequest()->getParams() as $key=>$value) {
+ echo '<dt><strong>Param: </strong>'.htmlspecialchars($key).'</dt>';
+ echo '<dt><strong>Value: </strong>'.htmlspecialchars($value).'</dt>';
+ }
+ echo '</dl>';
+ }
+}
+?>
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Helloworld/etc/config.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Helloworld/etc/config.xml Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,18 @@
+<config>
+ <modules>
+ <Magentotutorial_Helloworld>
+ <version>0.1.0</version>
+ </Magentotutorial_Helloworld>
+ </modules>
+ <frontend>
+ <routers>
+ <helloworld>
+ <use>standard</use>
+ <args>
+ <module>Magentotutorial_Helloworld</module>
+ <frontName>helloworld</frontName>
+ </args>
+ </helloworld>
+ </routers>
+ </frontend>
+</config>
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/etc/modules/Magentotutorial_Configviewer.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/etc/modules/Magentotutorial_Configviewer.xml Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,8 @@
+<config>
+ <modules>
+ <Magentotutorial_Configviewer>
+ <active>true</active>
+ <codePool>local</codePool>
+ </Magentotutorial_Configviewer>
+ </modules>
+</config>
diff -r 98d31339093e -r fd26e7cbf555 magento/magento/app/etc/modules/Magentotutorial_Helloworld.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/etc/modules/Magentotutorial_Helloworld.xml Thu Jul 05 09:02:36 2012 +0000
@@ -0,0 +1,8 @@
+<config>
+ <modules>
+ <Magentotutorial_Helloworld>
+ <active>true</active>
+ <codePool>local</codePool>
+ </Magentotutorial_Helloworld>
+ </modules>
+</config>
And here are the new differences that cause the problem:
diff -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php
--- a/magento/magento/app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php Thu Jul 05 09:02:36 2012 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php Thu Jul 05 12:13:55 2012 +0000
@@ -3,7 +3,10 @@
public function indexAction() {
- echo 'Hello Index!';
+ // remove our previous echo
+ // echo 'Hello Index!';
+ $this->loadLayout();
+ $this->renderLayout();
}
diff -r fd26e7cbf555 magento/magento/app/code/local/Magentotutorial/Helloworld/simple_page.phtml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/code/local/Magentotutorial/Helloworld/simple_page.phtml Thu Jul 05 12:13:55 2012 +0000
@@ -0,0 +1,16 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title>Untitled</title>
+ <meta name="generator" content="BBEdit 9.2" />
+ <style type="text/css">
+ body {
+ background-color:#f00;
+ }
+ </style>
+</head>
+<body>
+
+</body>
+</html>
diff -r fd26e7cbf555 magento/magento/app/design/frontend/base/default/layout/local.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/magento/magento/app/design/frontend/base/default/layout/local.xml Thu Jul 05 12:13:55 2012 +0000
@@ -0,0 +1,7 @@
+<layout version="0.1.0">
+ <default>
+ <reference name="root">
+ <block type="page/html" name="root" output="toHtml" template="../../../../../code/local/Magentotutorial/Helloworld/simple_page.phtml" />
+ </reference>
+ </default>
+</layout>
Thanks in advance,
— Shlomi Fish
Change to:
Then move your simple_page.phtml to:
app/design/frontend/default/default/template/magentotutorial/helloworld/simple_page.phtml
That should fix everything, I’m not convinced the way you are references your template location was correct. It’s always best to stick to convention.
Hope that helps. 🙂