1

I am learning from tuts+ premium tutorials. i am using this link to get some output

http://127.0.0.1/folder/mage3/index.php/demo/index/sayHello

my xml file in config.xml

<frontend>
    <routers>
        <tutsplus_demo>
            <use>standard</use>
                <args>
                    <module>TutsPlus_Demo</module>
                        <frontName>demo</frontName>
                </args>
            </tutsplus_demo>
        </routers>
</frontend>

IndexController.php file code

<?php

class TutsPlus_Demo_IndexController extends Mage_Core_Controller_Front_Action {

    public function sayHelloAction() {

        echo "Hello World!";
    }
}

I want Hello world! in output but its showing me 404 page.

  • try using <demo> instead <tutsplus_demo> in config.xml. Also try with changing name to Tutsplus instead TutsPlus. Clear cache too – Anil Suthar May 19 '16 at 8:47
  • instead of echo please use Mage::log(print('Hello World', true)); and don't forget to enable log in admin backend. check your log file var/log/system.log – Charlie May 19 '16 at 9:13
0

Try this,

Tutsplus_Demo.xml

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

app/code/local/Tutsplus/Demo/Block/Index.php

<?php   
class Tutsplus_Demo_Block_Index extends Mage_Core_Block_Template{   

}

app/code/local/Tutsplus/Demo/controllers/IndexController.php

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

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

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

      $this->renderLayout(); 

    }
}

app/code/local/Tutsplus/Demo/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Tutsplus_Demo>
      <version>0.1.0</version>
    </Tutsplus_Demo>
  </modules>
  <frontend>
    <routers>
      <demo>
        <use>standard</use>
          <args>
            <module>Tutsplus_Demo</module>
            <frontName>demo</frontName>
          </args>
      </demo>
    </routers>
        <layout>
          <updates>
            <demo>
              <file>demo.xml</file>
            </demo>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <demo>
        <class>Tutsplus_Demo_Helper</class>
      </demo>
    </helpers>
    <blocks>
      <demo>
        <class>Tutsplus_Demo_Block</class>
      </demo>
    </blocks>
  </global>
</config> 

app/code/local/Tutsplus/Demo/Helper/Data.php

<?php
class Tutsplus_Demo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

app/design/frontend/customtpackage/theme/layout/demo.xml

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

app/design/frontend/customtpackage/theme/template/demo/index.phtml

<?php echo "Hello word";?>
0

Try this file along with directory naming structure.In your case its important to take care of it.

1) app\etc\modules\TutsPlus_Demo.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <modules>
        <TutsPlus_Demo>
            <active>true</active>
            <codePool>local</codePool>
        </TutsPlus_Demo>
    </modules>
</config>

2) app\code\local\TutsPlus\Demo\etc\config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <frontend>
        <routers>
            <tutsplus_demo>
                <use>standard</use>
                <args>
                    <module>TutsPlus_Demo</module>
                    <frontName>demo</frontName>
                </args>
            </tutsplus_demo>
        </routers>
    </frontend>
</config>

3) app\code\local\TutsPlus\Demo\controllers\IndexController.php

class TutsPlus_Demo_IndexController extends Mage_Core_Controller_Front_Action
{
    public function sayHelloAction() {

        echo "Hello World!";
    }
}

Hope this will help you to identify you mistakes.

Following is the output which i get from above code.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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