Magento Custom Helper 不工作,为什么?

Magento Custom Helper not working, why?

正在尝试调试我的 Magento 自定义助手(使用 1.9CE 顺便说一下) Mag 是我自定义模块的名称。

/code/local/Mag/Layout/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mag_Layout>
            <version>1.0</version>
        </Mag_Layout>
    </modules>
    <global>
        <page>
            <layouts>
                <Mag_HomeLayout translate="label">
                    <label>Static ( Menu Left )</label>
                    <template>page/static-left.phtml</template>
                    <layout_handle>Static </layout_handle>
                </Mag_HomeLayout>
            </layouts>
        </page>
        <helpers>
            <nav>
                Mag_Nav_Helper
            </nav>
        </helpers>
    </global>
</config>

/code/local/Mag/Nav/Data.php

<?php

class Mag_Nav_Helper_Data extends Mage_Core_Helper_Abstract
{
    // Navigation helper
    public function getNavigation()
    {
        echo "here"; exit;
        echo "FOUND". $url;
        exit;
    }
}

然后在任何布局中我都试图调用它: 像这样:

<?php

$helper = Mage::helper('nav');
$helper->getNavigation();
?>

期望它会调用我的自定义辅助方法,但它没有,我在这里忽略了什么?谢谢!

编辑:还有从静态块调用助手的简单方法吗?

可能是 typo/naming 约定问题。 我会让模块中的所有名称统一:

<?xml version="1.0"?>
<config>
    <modules>
        <Mag_Nav>
            <version>0.1.0</version>
        </Mag_Nav>
    </modules>
    <global>
        <helpers>
            <mag_nav>
                <class>Mag_Nav_Helper</class>
            </mag_nav>
        </helpers>
    </global>
</config>

用法:

$oHelper= Mage::helper( 'mag_nav' );

别忘了编辑您的 app/etc/local/modules/Mag_Nav。xml