This Question is asked many times but still it's unresolved with definite solution. I am following this tutorial to implement the module http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-5.html.
I am getting this error
Fatal error: Call to a member function load() on a non-object in C:\wamp\www\magentoapp\app\code\local\Mudit\Weblog\controllers\IndexController.php on line 9
while trying to fetch the data from the database table in the IndexController.php while others get this error in core files of magento abstract.php
Please, check the code for the config.xml, Blogpost.php and IndexController.php.
Please, help I am stuck with this from last 2 hours.
etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
The module's node contains basic
information about each Magento module
-->
<modules>
<!--
This must exactly match the namespace and module's folder
names, with directory separators replaced by underscores
-->
<Mudit_Weblog>
<!-- The version of our module, starting at 0.0.1 -->
<version>0.0.1</version>
</Mudit_Weblog>
</modules>
<frontend>
<routers>
<weblog>
<use>standard</use>
<args>
<module>Mudit_Weblog</module>
<frontName>weblog</frontName>
</args>
</weblog>
</routers>
</frontend>
<global>
<models>
<weblog>
<class>Mudit_Weblog_Model</class>
<!--
need to create our own resource, can't just
use core_resource
-->
<resourceModel>weblog_resource</resourceModel>
</weblog>
<weblog_resource>
<class>Mudit_Weblog_Model_Resource</class>
<entities>
<blogpost>
<table>blog_posts</table>
</blogpost>
</entities>
</weblog_resource>
</models>
</global>
Model/Blogpost.php
class Mudit_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init('weblog/blogpost');
}
}
Model/Resource/Blogpost.php
<?php class Mudit_Weblog_Model_Resource_Blogpost extends Mage_Core_Model_Resource_Db_Abstract
{
public function _construct()
{
$this->_init('weblog/blogpost', 'blogpost_id');
}
}
?>
Controllers/IndexController.php
<?php class Mudit_Weblog_IndexController extends Mage_Core_Controller_Front_Action
{
public function testModelAction()
{
$params = $this->getRequest()->getParams();
$blogpost = Mage::getModel('weblog/blogpost');
echo("Loading the blogpost with an ID of ".$params['id']);
$blogpost->load($params['id']);
$data = $blogpost->getData();
var_dump($data);
}
}
?>
Magentotutorial/Weblog/Model/Blogpost.php
?