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 为什么apriori的运行时间会比fp growth的运行时间短呢
  • ¥15 帮我解决一下膳食平衡的线性规划模型的数据实例
  • ¥40 万年历缺少农历,需要和阳历同时显示
  • ¥250 雷电模拟器内存穿透、寻基址和特征码的教学
  • ¥200 比特币ord程序wallet_constructor.rs文件支持一次性铸造1000个代币,并将它们分配到40个UTXO上(每个UTXO上分配25个代币),并设置找零地址
  • ¥15 关于Java的学习问题
  • ¥15 如何使用chatgpt完成文本分类任务?
  • ¥15 已知速度v关于位置s的等式,怎么转化为已知位置求速度v的等式
  • ¥15 我有个餐饮系统,用wampserver把环境配置好了,但是后端的网页却进去,是为什么,能不能帮远程一下?
  • ¥15 R运行没有名称为"species"的插槽对于此对象类"SDMmodelCV"