2
votes

Hoping someone could help me out with a test Magento custom module that I'm having no luck getting to output. The module shows up in Configuration > Advanced, so I assumed the Helloworld_Mystuff.xml was done properly but I could be wrong! I disabled all cache on my local Magento admin instance. Flushed the cache a number of times, logged in/out of admin, differ browsers. I'm on a Mac using apache if it matters.

/etc/modules/Helloworld_Mystuff.xml (excluded the xml line)

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

/app/code/local/Helloworld/Mystuff/controllers/IndexController.php

class Helloworld_Mystuff_IndexController extends Mage_Core_Controller_Front_Action{
  public function indexAction(){
    echo "test";
    //$this->loadLayout()->renderLayout();
  }
}

/app/code/local/Helloworld/Mystuff/etc/config.xml

<config> 
    <modules>
        <Helloworld_Mystuff>
            <version>0.0.1</version>
        </Helloworld_Mystuff>
    </modules>
     <frontend>
                <routers>
                    <helloworld>
                        <use>standard</use>
                        <args>
                              <module>Helloworld_Mystuff</module>
                              <frontName>helloworld</frontName>
                        </args>
                    </helloworld>
                </routers>
     </frontend>
</config>

Tried doing
- /helloworld/index
- /helloworld/index/index

and it resulted in a 404 error.

I tried putting some debug code in the /varien/Router/Standard.php to see which class it was looking for when I called my test URL, and it was looking for Mage_Cms_IndexController. So somewhere along the lines my custom module is not loading because Magento doesn't even attempt to load the file.

EDIT: I added some additional debug code in the Varien/Router/Standard.php within the function:

public function match(Zend_Controller_Request_Http $request)
{
//checking before even try to find out that current module
//should use this router
if (!$this->_beforeModuleMatch()) {
    return false;
}

$this->fetchDefault();

$front = $this->getFront();
$path = trim($request->getPathInfo(), '/');

if ($path) {
    $p = explode('/', $path);
} else {
    $p = explode('/', $this->_getDefaultPath());
}
echo "<br />front = " . ($front);
echo "<br />path = " . ($path);
echo "<br />request->getModuleName = ".$request->getModuleName();

Output

front =
path = helloworld/index
request->getModuleName =
front =
path = helloworld/index
request->getModuleName =
front =
path = helloworld/index
request->getModuleName = cms
front =
path = helloworld/index
request->getModuleName = cms 
4

4 Answers

3
votes

Drop some debugging code in the following method (the var_dumps)

#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
    $controllerFileName = $this->getControllerFileName($realModule, $controller);
    var_dump($controllerFileName);
    if (!$this->validateControllerFileName($controllerFileName)) {
        return false;
    }

    $controllerClassName = $this->getControllerClassName($realModule, $controller);
    var_dump($controllerClassName);
    if (!$controllerClassName) {
        return false;
    }

    // include controller file if needed
    if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
        return false;
    }

    return $controllerClassName;
}

This will tell you which classes/files Magento is looking for when it tries to route your URLs, and is usually enough to ferret out the typo in your configuration and/or class name and/or filename.

0
votes

Try using this in /app/code/local/Helloworld/Mystuff/etc/config.xml

<config> 
  <modules>
    <Helloworld_Mystuff>
      <version>0.0.1</version>
    </Helloworld_Mystuff>
  </modules>
  <frontend>
    <routers>
      <mystuff>
        <use>standard</use>
        <args>
          <module>Helloworld_Mystuff</module>
          <frontName>helloworld</frontName>
        </args>
      </mystuff>
    </routers>
  </frontend>
</config>
0
votes

Sorry guys, this was something really stupid, my config file was named incorrectly. Alan's tip helped me realize the router wasn't being picked up so I went back from scratch.

I printed out all the router names Magento picked up and saw my module wasn't in there.

foreach ($routers as $routerName=>$routerConfig) {
echo $routerName;
0
votes

I have the same problem and in my case it's all about case sensitive words, I think yours too:
try this

<frontend>
     <routers>
           <Mystuff>
                <use>standard</use>
                <args>
                     <module>Helloworld_Mystuff</module>
                     <frontName>helloworld</frontName>
                </args>
           </Mystuff>
     </routers>
</frontend>

here is my question