1

the etc/config.xml file content is :

<config>
    <global>
        <modules>
                <attila3_helloworld>
                        <version>0.1.0</version>
                </attila3_helloworld>
        </modules>
        <blocks>
            <helloworld>
                <rewrite>
                    <helloworld>Attila3_HelloWorld_Block_HelloWorld</helloworld>
                </rewrite>
            </helloworld>
        </blocks>
    </global>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Attila3_HelloWorld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>
        <layout>
            <updates>
                <helloworld>
                    <file>helloworld.xml</file>
                </helloworld>
            </updates>
        </layout>
    </frontend>
</config>

The IndexController content is :

<?php
    class Attila3_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action{

        public function indexAction(){
            $this->loadLayout(array('default'));
            $this->renderLayout();
        }
    }

the Block/HelloWorld.php content is :

<?php 
    class Attila3_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template{
        // aici vor fi metodele
    }

the etc/modules/Attila3_HelloWorld.xml content is :

<config>
    <modules>
        <Attila3_HelloWorld>
            <active>true</active>
            <codePool>local</codePool>
        </Attila3_HelloWorld>
    </modules>
</config>  

the layout/helloworld.xml content is :

<?xml version="1.0"?>

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

and finnaly the template/helloworld/helloworld.html content is : "Hello World ! I am a Magento Guy." So I want to display that string when I access this link :http://attin.netlogiq.info/magento/index.php/helloworld. As you can see the result is different? can someone help me with this ? thx

this is the result : enter image description here

2
  • I followed this example : magento4u.wordpress.com/2009/06/08/… Commented May 9, 2014 at 11:59
  • You dont need use the rewrite method for this simple one. rewrite is used for over ride the existing classes. And that bolg is very old one. Things are changed now. If you want to create simple module, then follow my answers below.
    – Elavarasan
    Commented May 9, 2014 at 12:09

3 Answers 3

2

Why did you use rewrite for this ..? You want create simple module right ..? Then follow as below, Your package name = Attila3 and module name = HelloWorld.

This is your front end block class and it inherits from Mage_Core_Block_Template. And every frontend block's should be inherits from this class only. Your app->code->local->Attila3->HelloWorld->Block->Index.php

<?php   
class Attila3_HelloWorld_Block_Index extends Mage_Core_Block_Template{   


}

This is your controller for your module. And all frontend actions are inherits from this class Mage_Core_Controller_Front_Action

Your app->code->local->Attila3->HelloWorld->controllers->IndexController.php

<?php
class Attila3_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action{
    public function IndexAction() {

      $this->loadLayout();   
      $this->getLayout()->getBlock("head")->setTitle($this->__("My title"));
            $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
      $breadcrumbs->addCrumb("home", array(
                "label" => $this->__("Home Page"),
                "title" => $this->__("Home Page"),
                "link"  => Mage::getBaseUrl()
           ));

      $breadcrumbs->addCrumb("my title", array(
                "label" => $this->__("My title"),
                "title" => $this->__("My title")
           ));

      $this->renderLayout(); 

    }
}

And this is your module configuration file. Your app->code->local->Attila3->HelloWorld->etc->config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Attila3_HelloWorld>
      <version>0.1.0</version>
    </Attila3_HelloWorld>
  </modules>
  <frontend>
    <routers>
      <helloworld>
        <use>standard</use>
          <args>
            <module>Attila3_HelloWorld</module>
            <frontName>helloworld</frontName>
          </args>
      </helloworld>
    </routers>
        <layout>
          <updates>
            <helloworld>
              <file>helloworld.xml</file>
            </helloworld>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <helloworld>
        <class>Attila3_HelloWorld_Helper</class>
      </helloworld>
    </helpers>
    <blocks>
      <helloworld>
        <class>Attila3_HelloWorld_Block</class>
      </helloworld>
    </blocks>
  </global>
</config> 

This is your helper class. And this is not need now. But its a good practice to declare every thing that should used in future.. Your app->code->local->Attila3->HelloWorld->Helper->Data.php

<?php
class Attila3_HelloWorld_Helper_Data extends Mage_Core_Helper_Abstract
{
}

And it defines the layout blocks for your module. Your app->design->frontend->default->YOUR THEME NAME->layout->heloworld.xml

<?xml version="1.0"?>   
<layout version="0.1.0">   
  <helloworld_index_index>   
    <reference name="root">   
      <action method="setTemplate"><template>page/1column.phtml</template></action>   
    </reference>   
    <reference name="content">   
      <block type="helloworld/index" name="helloworld_index" template="helloworld/index.phtml"/>   
    </reference>   
  </helloworld_index_index>   
</layout> 

And this is your phtml file, and currently it displays your data. Your app->design->frontend->default->YOUR THEME NAME->template->heloworld->index.phtml

<p>Hello World ! I am a Magento Guy.</p>

Then finally you need to activate your module. And it is in local pool.So, app->etc->modules->Attila3_HelloWorld.xml

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

Thats it..!cheers..!

2
  • hey ! Im updated with an image my post with the result of your code ! I copy pasted your code ! :) Commented May 12, 2014 at 9:01
  • and i changed the theme from default to Attila3 in Admin->Design Commented May 12, 2014 at 9:20
0

In your config.xml append the below code. You need to define your block class in config.xml

    <global>
    . . . . 
    <blocks>
 . . . .
                <helloworld>
                    <class>Attila3_HelloWorld_Block</class>
                </helloworld>
            </blocks>
        </global>

Note: Make sure to define blocks, models, and helpers in config.xml

1
  • I made this changes as you sugested , but still nothing Commented May 12, 2014 at 8:42
0

In your config.xml file make following change

<blocks>
    <helloworld>
        <class>Attila3_HelloWorld_Block</class>
    </helloworld>
</blocks>

In your block helloworld.php page make a function

public function function1(){
    return "String";
}

In your phtml file call this block function as

echo $this->function1();
1
  • still nothing :( Commented May 9, 2014 at 12:55

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.