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 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波