Question

I have overridden the 'customer' frontname in order to make my custom module pages display as /customer/my-page-action/. When I do that my Helper class cannot be found:

Warning: include(Mage/FranchiseSelect/Helper/Data.php): failed to open stream: No such file or directory

Here's my extension config:

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

Here's my module config:

<?xml version="1.0" encoding="utf-8" ?>
<config>
  <modules>
    <Rhino_FranchiseSelect>
      <version>0.1.0</version>
    </Rhino_FranchiseSelect>
  </modules>
  <frontend>
    <routers>
      <customer>
        <args>
          <modules>
            <franchise before="Mage_Customer">Rhino_FranchiseSelect</franchise>
          </modules>
        </args>
      </customer>
    </routers>
    <events>
      <customer_session_init>
        <observers>
          <sessioninit_handler>
            <type>singleton</type>
            <class>Rhino_FranchiseSelect_Model_Observer</class>
            <method>redirectToFranchise</method>
          </sessioninit_handler>
        </observers>
      </customer_session_init>
      <controller_action_predispatch_customer_account_create>
        <observers>
              <handler>
                    <type>singleton</type>
                    <class>Rhino_FranchiseSelect_Model_Observer</class>
                    <method>checkForRegion</method>
              </handler>
        </observers>
      </controller_action_predispatch_customer_account_create>
      </events>
  </frontend>
  <global>
    <resources>
      <helpers>
          <what_should_this_tag_name_be>
              <class>Rhino_FranchiseSelect_Helper</class>
          </what_should_this_tag_name_be>
        </helpers>
    </resources>
  </global>
</config>

My helper is located here: /app/code/local/Rhino/FranchiseSelect/Helper/Data.php

I'm trying to instantiate it like so:

$helper = Mage::helper("what-should-this-path-be");

I'm not sure what the config helper alias tag name or helper path name should be in order to get this to work. Can you help me identify how this should be structured?

Was it helpful?

Solution

I'm not 100% sure it's the additional router configuration that's triggering this error — off the top of my head there's nothing in the controller dispatch process that instantiates a helper.

The most common reason for Magento to automatically instantiate a helper is a modules="helperalias" attribute in a configuration file. This indirectly invokes a helper's __ localization method.

Without knowing why your Magento system wants to instantiate a helper, it's impossible to know what the alias should be. If I was you I'd temporarily add something debugging code to the following file

#File: app/Mage.php
public static function helper($name)
{ 
    //poor man's logging
    file_put_contents('/tmp/test.log',"$name\n",FILE_APPEND);

    // PHP's equivalent of printf debugging
    var_dump($name);

    $registryKey = '_helper/' . $name;
    if (!self::registry($registryKey)) {
        $helperClass = self::getConfig()->getHelperClassName($name);
        self::register($registryKey, new $helperClass);
    }
    return self::registry($registryKey);
}

This will tell you what the helper's alias is, which is turn is what you should name the configuration node you're looking for.

Update: Based on the comment below, you want

<global>
    <helpers>
        <franchiseselect>
            <class>Rhino_FranchiseSelect_Helper</class>
        </franchiseselect>
    </helpers>
</global>

When you say

Mage::helper('franchiseselect');

What you're really saying is

Mage::helper('franchiseselect/data');

Magento substitutes the data string automatically. The franchiseselect string is the alias group name, the data string is the alias model name. When you add the node <franchiseselect>/<what_should_this_tag_name_be/> always to your XML you're defining the alias group name.

Also, your XML had an extra node, <resources/>, under the <helpers/> node — you don't need that.

As for why the Magento looked for a class under Mage — if Magento can't find a configured alias, it automatically guesses that the request was for a class under the Mage namespace. This guess is a bit of paranoid programming on the part of the original core team to ensure any misconfigurations in their own modules didn't trigger errors. When Magento couldn't find your framework helper, it tried instantiating a Mage_Framework... class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top