0

I am not so familer with magento so i am trying to develop a simple module on magento 1.9.1 with help of this tutorial http://magentotutorial.net/magento-tutorial-how-to-create-a-simple-module/
but i am facing a problem with display the text in frontend with layout & templates(phtml file) if i write simple

echo "hello"; 

in

indexAction() of IndexController.php

it display simple hello text on blank screen without any magento template on url sitename.com/hello

enter image description here

but if write

$this->loadLayout();
$this->renderLayout();

it display my theme layout with any content in content area enter image description here

here is my codes
app/code/etc/modules/Dinesh_hello.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Dinesh_Hello>
 <active>true</active>
 <codePool>local</codePool>
 </Dinesh_Hello>
 </modules>
</config>


app/code/local/Dinesh/etc/config.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Dinesh_Hello>
 <version>0.1.0</version>
 </Dinesh_Hello>
 </modules>
 <global>
 </global>
 <frontend>
 <routers>
 <dinesh_hello>
 <use>standard</use>
 <args>
 <module>Dinesh_Hello</module>
 <frontName>hello</frontName>
 </args>
 </dinesh_hello>
 </routers>
<layout>
 <updates>
 <hello>
 <file>hello.xml</file>
 </hello>
 </updates>
 </layout>
 </frontend>
 <global>
 <blocks>
 <hello>
 <class>Dinesh_Hello_Block</class>
 </hello>
 </blocks>
 </global>
</config>

app/code/local/Dinesh/controllers/IndexController.php

<?php 
class Dinesh_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
 public function indexAction()
 {
 $this->loadLayout();
 $this->renderLayout();
 //echo "hello";
 }
}
?>

app/code/local/Dinesh/Block/Hello.php

<?php
class Dinesh_Hello_Block_Hello extends Mage_Core_Block_Template
{
 public function methodblock()
 {
 return ‘informations about my block !!’ ;
 }
}
?>

app/design/frontend/default/default/layout/hello.xml

<layout version="0.1.0′′>
 <hello_index_index>
 <reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
 </reference>
 <reference name="content">
 <block type="hello/hello" name="hello" template="hello/hello.phtml"/>
 </reference>
 </hello_index_index>
</layout>

app/design/frontend/default/default/template/hello/hello.phtml

<?php
echo $this->methodblock();
//echo "hello";
?>
asked Jun 10, 2015 at 7:41
5
  • check log for the error? Commented Jun 10, 2015 at 7:48
  • please set path hint as yes and check your phtml call or not Commented Jun 10, 2015 at 7:52
  • @ND17 i already try this , phtml is not calling Commented Jun 10, 2015 at 7:57
  • @QaisarSatti there is no log file at my magento system Commented Jun 10, 2015 at 8:11
  • search how to enable error log too Commented Jun 10, 2015 at 8:16

2 Answers 2

2

Tested and working follow this..

config.xml

<?xml version="1.0"?>
<config>
 <modules>
 <Dinesh_Hello>
 <version>0.1.0</version>
 </Dinesh_Hello>
 </modules>
 <frontend>
 <routers>
 <hello>
 <use>standard</use>
 <args>
 <module>Dinesh_Hello</module>
 <frontName>hello</frontName>
 </args>
 </hello>
 </routers>
 <layout>
 <updates>
 <hello>
 <file>hello.xml</file>
 </hello>
 </updates>
 </layout>
 </frontend>
 <global>
 <blocks>
 <hello>
 <class>Dinesh_Hello_Block</class>
 </hello>
 </blocks> 
 </global>
</config>

hello.xml

<?xml version="1.0"?>
<layout version='0.1.0'>
 <hello_index_index>
 <reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
 </reference>
 <reference name="content">
 <block type="hello/hello" name="hello" template="hello/hello.phtml"/>
 </reference>
 </hello_index_index>
</layout>

Block/Hello.php

<?php
class Dinesh_Hello_Block_Hello extends Mage_Core_Block_Template
{
 public function methodblock()
 {
 return 'informations about my block !!' ;
 }
}
?>

controllers/IndexController.php

<?php 
class Dinesh_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
 public function indexAction()
 {
 $this->loadLayout();
 $this->renderLayout();
 }
}
?>
answered Jun 10, 2015 at 8:15
5
  • i apply this changes & also convert other " " to " " in hello.xml but it display only blank page without any message/text Commented Jun 10, 2015 at 8:26
  • in phtml write simple echo "hello"; u r getting this or not Commented Jun 10, 2015 at 8:30
  • update answer check ti Commented Jun 10, 2015 at 9:02
  • @QaisarSatti try this also try echo "hello" in phtml but still showing plane blank page without any template layout Commented Jun 10, 2015 at 9:33
  • did you changed the files that i recommended? hello.xml and config.xml Commented Jun 10, 2015 at 9:37
0

Change your etc/config.xml to this-

<?xml version="1.0"?>
<config>
 <modules>
 <Dinesh_Hello>
 <version>0.1.0</version>
 </Dinesh_Hello>
 </modules>
 <frontend>
 <routers>
 <hello>
 <use>standard</use>
 <args>
 <module>Dinesh_Hello</module>
 <frontName>hello</frontName>
 </args>
 </hello>
 </routers>
 <layout>
 <updates>
 <hello>
 <file>hello.xml</file>
 </hello>
 </updates>
 </layout>
 </frontend>
 <global>
 <blocks>
 <hello>
 <class>Dinesh_Hello_Block</class>
 </hello>
 </blocks>
 </global>
</config>
answered Jun 10, 2015 at 8:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.