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

时间:2015-03-11 18:06:09

标签: php magento

我有以下错误消息:

  

致命错误:在第225行的/home/autoco/public_html/shop/app/code/core/Mage/Core/Model/Abstract.php中调用非对象上的成员函数load()

如何解决这个问题?

<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>

模特课程:

<?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);
  }

}

资源类:

<?php

class Becker_Tec_Model_Resource_Manufacturers extends    Mage_Core_Model_Resource_Db_Abstract {

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

} 

测试页面

<?php

require_once("app/Mage.php");

Mage::app();

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

1 个答案:

答案 0 :(得分:0)

<tec_resource>

是罪魁祸首,因为它没有认识到如何连接你的电话。

首先使用相同的命名约定来避免让自己疯狂。

配置xml模型部分:

<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>

模特课程:

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

资源类:

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

集合类:(如果你想使用内置的集合机制)

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' );
    }

将它们放在适当的文件夹中,然后您就可以致电:

$oTec = Mage::getModel( 'becker_tec/tec' );