dongyinzheng6572 2015-03-11 18:06
浏览 58
已采纳

Magento错误:在非对象上调用成员函数

I have this error message:

Fatal error: Call to a member function load() on a non-object in /home/autoco/public_html/shop/app/code/core/Mage/Core/Model/Abstract.php on line 225

How to fix this?

<config>
<modules>
    <Becker_Tec>
        <version>1.0.0</version>
    </Becker_Tec>
</modules>
<global>
    <models>
        <tec>
            <class>Becker_Tec_Model</class>
            <resourceModel>tec_resource</resourceModel>
            <tec_resource>
                <class>Becker_Tec_Model_Resource</class>
                <entities>
                    <manufacturers>
                        <table>tof_manufacturers</table>
                    </manufacturers>
                </entities>
            </tec_resource>
        </tec>
    </models>
</global>
<frontend>
    <routers>
        <becker_tec>
            <use>standard</use>
            <args>
                <module>Becker_Tec</module>
                <frontName>tecdoc</frontName>
            </args>
        </becker_tec>
    </routers>
 </frontend>
</config>

Model class:

<?php
class Becker_Tec_Model_Manufacturers extends Mage_Core_Model_Abstract
{

  protected function _construct()
   {
    $this->_init('tec/manufacturers');
   }
  public function test(){
    $this->getCollection()->load(15);
  }

}

Resource class:

<?php

class Becker_Tec_Model_Resource_Manufacturers extends    Mage_Core_Model_Resource_Db_Abstract {

  protected function _construct()
   {
    $this->_init('tec/manufacturers', 'tof_manufacturers_id');
   }

} 

Test Page:

<?php

require_once("app/Mage.php");

Mage::app();

$data = Mage::getModel("tec/manufacturers");
$data->load(136);
print_r($data);
  • 写回答

1条回答 默认 最新

  • dongzuo9096 2015-03-12 01:01
    关注
    <tec_resource>
    

    Was the culprit as it didn't recognize how to hook up your call.

    First of all use the same naming convention to avoid driving yourself mad.

    Config xml model section:

    <models>
        <becker_tec>
            <class>Becker_Tec_Model</class>
            <resourceModel>becker_tec_resource</resourceModel>
        </becker_tec>
        <becker_tec_resource>
            <class>Becker_Tec_Model_Resource</class>
            <entities>
                <becker_tec>
                    <table>becker_tec</table>
                </becker_tec>
            </entities>
        </becker_tec_resource>
    </models>
    

    Model Class:

    class Becker_Tec_Model_Tec extends Mage_Core_Model_Abstract 
    {
        protected function _construct()
        {
            $this->_init( 'becker_tec/tec' );
        }   
    

    Resource class:

    class Becker_Tec_Model_Tec_Resource_Tec extends Mage_Core_Model_Resource_Db_Abstract
    {
        protected function _construct()
        {
            $this->_init( 'becker_tec/tec', 'entity_id' );
        }
    

    Collection class: ( If you want to use built in collection mechanisms )

    class Becker_Tec_Model_Tec_Resource_Tec_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
    {
        public function _construct()
        {
            parent::_construct();
            $this->_init( 'becker_tec/tec' );
        }
    

    Place them in the appropriate folders and you'll be able to call:

    $oTec = Mage::getModel( 'becker_tec/tec' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c