3

I'm new to Magento. I'm learning to add custom Module. I have created a custom module and able to load the controller. Now i'm learning to add Blocks and Layouts. I have added the files but i'm not getting the expected output.

I have used namespace 'Nikhil' and the Module name is 'MyModule'.

When it's executed, I can see the webpage, there are no errors. But its not showing the string "MyModule Block" or its not logging the message 'i'm in Block'.

I have spend several hours debugging it. Please help

The contents of the configuration file in \test\app\etc\modules\Nikhil_MyMdoule.xml is:

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

Config File: app\code\local\Nikhil\MyModule\etc\config.xml

<?xml version="1.0"?> <config> <modules> <Nikhil_MyModule> <version>0.0.1</version> </Nikhil_MyModule> </modules> <frontend> <routers> <mymodule> <use>standard</use> <args> <module>Nikhil_MyModule</module> <frontName>nikhil</frontName> </args> </mymodule> </routers> <layout> <updates> <mymodule> <file>mymodule.xml</file> </mymodule> </updates> </layout> </frontend> <global> <blocks> <mymodule> <class>Nikhil_MyModule_Block</class> </mymodule> </blocks> </global> </config> 

Controller: app\code\local\Nikhil\MyModule\controllers\IndexController.php

 class Nikhil_MyModule_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { Mage::log('im in Controller'); $this->loadLayout(); $this->renderLayout(); Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles()); } public function testAction(){ echo "custom function"; } } 

Block file: app\code\local\Nikhil\MyModule\Block\MyBlock.php

class Nikhil_MyModule_Block_MyBlock extends Mage_Core_Block_Template { public function myfunction(){ Mage::log('im in Block'); return "MyModule Block"; } } 

Sorry missed to add following files.

\app\design\frontend\base\layout\mymodule.xml

<code> <?xml version="1.0"?> <layout version="0.1.0"> <mymodule_index_index> <reference name="content"> <block name="myblock" template="mymodule/mymodule.phtml" type="mymodule/myblock"/> </reference> </mymodule_index_index> </layout> </code> 

And from \app\design\frontend\base\template\mymodule.phtml

echo $this->myfunction(); 

I'm trying to call the index Action

13
  • Which action are you looking access in the controller index or test? And can you post the content of your layout update - mymodule.xml Commented Jan 15, 2016 at 12:11
  • You need to define layout file and add your block in to it for your controller handler. In your config.xml it seems mymodule.xml Commented Jan 15, 2016 at 12:11
  • The method myfunction() is nowhere called. This should typically be called in a template. Can you add the contents of the mymodule.xml layout file and the contents of your template (.phtml file)? Commented Jan 15, 2016 at 12:13
  • I'm trying to call indexAction. I have created a layout file and put it in \app\design\frontend\base\layout\mymodule.xml. I have edited the question to add the details. And also created a phtml which i have put in app\design\frontend\base\template\mymodule.phtml Commented Jan 15, 2016 at 12:28
  • Put it here .app\design\frontend\base\default\layout\mymodule.xml and template file in app\design\frontend\base\default\template\mymodule.phtml Commented Jan 15, 2016 at 12:31

1 Answer 1

3

First, enable logging from the admin, and see if it produces any files inside "var/log" folder. If not, there might be some permission issues on the folder.

Now, back to your problem, your layout file is telling Magento to search for the template file mymodule/mymodule.phtml, so if you are going with the base theme folder, path for your template file will be app\design\frontend\base\template\mymodule\mymodule.phtml.

1
  • Thanks that resolved the issue... There was slight change in the path. app\design\frontend\base\default\template\mymodule\mymodule.phtml.I wanted to up up vote you. But since i do not have enough reputation i can't. I but i will do it once i have the reputation. Thanks again Commented Jan 17, 2016 at 13:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.