开发者

Magento - Trouble with setting up Model Read Adapter

开发者 https://www.devze.com 2023-01-12 02:35 出处:网络
I was following through on Alan Storm\'s tutorial on Magento\'s Model and ORM basics and I\'ve run into a bit of a problem. When I get to the portion where I load from the Mod开发者_如何学编程el for t

I was following through on Alan Storm's tutorial on Magento's Model and ORM basics and I've run into a bit of a problem. When I get to the portion where I load from the Mod开发者_如何学编程el for the first time I get this error "Fatal error: Call to a member function load() on a non-object...". I've reset everything already and tried again from scratch but I still get the same problem. My code looks like this:

 $params = $this->getRequest()->getParams();
 $blogpost = Mage::getModel('weblog/blogpost');
 var_dump($blogpost);
 echo("Loading the blogpost with an ID of ".$params['id']);
 $blogpost->load($params['id']);

As you can see I dumped the contents of $blogpost and it shows that it is just a boolean false. My guess is that there's either a problem with the connection to the database or, for some reason, the code for Mage::getModel() didn't get installed correctly.

EDIT - Adding Code

There's so many that I just decided to pastebin them lol

app/code/local/Ahathaway/Weblog/controllers/IndexController.php

app/code/local/Ahathaway/Weblog/etc/config.xml

app/code/local/Ahathaway/Weblog/Model/Blogpost.php

app/etc/modules/Ahathaway_Weblog.xml


Your Model/Blogpost.php file should actually be Model/Mysql4/Blogpost.php, and you are missing the real Model/Blogpost.php.


My guess is that Mage cannot find your model class. Double check the module/model name and also verify if the model is in a correct place in the filesystem (it should be in app/code/local/Weblog/Model/Blogpost.php).

You also need to check if your config.xml correctly defines your model classes. It would be best if you could past your config.xml and your model class...


A quick glance reveals you're missing the model resource. Go back to the section around the following code example

File: app/code/local/Alanstormdotcom/Weblog/Model/Mysql4/Blogpost.php

class Alanstormdotcom_Weblog_Model_Mysql4_Blogpost extends Mage_Core_Model_Mysql4_Abstract{
    protected function _construct()
    {
        $this->_init('weblog/blogpost', 'blogpost_id');
    }   
}
0

精彩评论

暂无评论...
验证码 换一张
取 消