【问题标题】:Magento getModel return falseMagento getModel 返回 false
【发布时间】:2014-06-05 07:01:48
【问题描述】:

我阅读并关注this guide

但是这个错误:

致命错误:在 C:\wamp\www\Ishop\app\code\core\Mage\Core\Model\Abstract.php 第 225 行的非对象上调用成员函数 load()

这是 config.xml

<models>
        <weblog>
            <class>Magentotutorial_Weblog_Model</class>
            <resourceModel>weblog_resource</resourceModel>
        </weblog>
         <weblog_resource>
            <class>Magentotutorial_Weblog_Model_Resource</class>
            <entities>
                <blogpost>
                    <table>blog_posts</table>
                </blogpost>
            </entities>
        </weblog_resource>
  </models>

我添加了名为 blog_posts 的表。我是 Magento 的新手。是调试这个问题的方法吗?我认为config.xml 文件中有错误。但是我检查了几次,仍然没有发现错误。

【问题讨论】:

  • 您是否可以通过传递 ID 来加载博文?
  • 把所有模型文件也放到这里config.xml

标签: magento


【解决方案1】:

您的一个模型中似乎存在问题。

你应该有一个文件 app/code/local/Magentotutorial/Weblog/Model/Blogpost.php:

<?php
    class Magentotutorial_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract
    {
        protected function _construct()
        {
            $this->_init('weblog/blogpost');
        }
    }
?>

还有一个文件app/code/local/Magentotutorial/Weblog/Model/Resource/Blogpost.php:

<?php
    class Magentotutorial_Weblog_Model_Resource_Blogpost extends Mage_Core_Model_Resource_Db_Abstract{
        protected function _construct()
        {
            $this->_init('weblog/blogpost', 'blogpost_id');
        }
    } 
?>

还有一个文件app/code/local/Magentotutorial/Weblog/Model/Resource/Blogpost/Collection.php:

<?php
    class Magentotutorial_Weblog_Model_Resource_Blogpost_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
        protected function _construct()
        {
                $this->_init('weblog/blogpost');
        }
    }
?>

【讨论】:

  • 我没有 Collection 类。我调试以查找模型资源中的错误。我打电话给 $blogpost = Mage::getResourceModel('weblog/blogpost'); $blogpost 的变量为 false。但我的 Model_resource 类与您的相同。当我调用 $blogpost = Mage::getResourceModel('weblog/blogpost') 时,我的屏幕调试显示“_init('weblog/blogpost', 'blogpost_id')”。我不知道这条线出现在哪里。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多