【问题标题】:magento can not load my custom modelmagento 无法加载我的自定义模型
【发布时间】:2015-07-01 05:11:24
【问题描述】:

嗨,我有一个我不明白的问题,请有人可以帮助我。 我在 1.8.1 我在 app->code->local->Mycompany 中有一个模块

  • 我的坎帕尼
    • 测试模型
        • config.xml
      • 型号
        • FirstModel.php

config.xml 中的代码

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_TestModel>
            <version>0.1.0</version>
        </Mycompany_TestModel>
    </modules>
    <global>
        <models>
            <TestModel>
                <class>Mycompany_TestModel_Model</class>
            </TestModel>
        </models>
    </global>
</config>

FirstModel.php 中的代码

class Mycompany_TestModel_Model_FirstModel extends Mage_Core_Model_Abstract {

    public function output()
    {
        echo "get";
    }
}

当我使用时

Mage::getModel('TestModel/FirstModel')

magento 无法加载类。

我测试过,它在我的本地机器上运行。

请帮忙。

另外。我也试过:

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_TestModel>
            <version>0.1.0</version>
        </Mycompany_TestModel>
    </modules>
    <global>
        <models>
            <testmodel> /* instead of <TestModel> */
                <class>Mycompany_TestModel_Model</class>
            </testmodel>
        </models>
    </global>
</config>

我还是什么都进不去

Mage::getModel('testmodel/FirstModel')

非常感谢。

【问题讨论】:

标签: magento magento-1.8


【解决方案1】:

当你使用 magento fatory 方法时 [Mage::getModel('testmodel/FirstModel') ]

这意味着您需要使用它来定义模型。

按照magento,当自动加载器执行testmodel/FirstModel时运行如下:

testmodel=Mycompany_TestModel_Model

和 FirsModel 错误,文件和名称应为 Firstmodel 模型文件夹后(Mycompany/TestModel/Model所有文件夹和文件名首字母大写after that all should be lower a

这意味着文件应该是

  • Firstmodel.php 而不是 FirstModel
  • testmodel/FirstModel 应该是testmodel/firstmodel
  • NO underscore 应该在 folders and file name 中使用

【讨论】:

  • 您可以使用 FirstModel 作为名称。我只是发现问题。编译器工具已启用,我需要重新构建它。
猜你喜欢
  • 2013-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多