I am new to Magento. Some questions make me crazy in the tutorial on their document.
1, How to open the development mode in magento 1.5.1?
2,”Fatal error: Call to a member function load() on a non-object in D:\PHPWeb\mag\app\code\local\Magentotutorial\Weblog\controllers\IndexController.php on line 7″
It means I can not instantiate a model object. Someone help me. This is my code below.
Controller:
class Magentotutorial_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);
}
}
Model:
class Magentotutorial_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract {
protected function _construct() {
$this->_init('weblog/blogpost');
}
}
Config.xml:
<config>
<modules>
<Magentotutorial_Weblog>
<version>0.1.0</version>
</Magentotutorial_Weblog>
</modules>
<frontend>
<routers>
<weblog>
<use>standard</use>
<args>
<module>Magentotutorial_Weblog</module>
<frontName>weblog</frontName>
</args>
</weblog>
</routers>
</frontend>
<models>
<weblog>
<class>Magentotutorial_Weblog_Model</class>
<!--
need to create our own resource, cant just
use core_mysql4
-->
<resourceModel>weblog_mysql4</resourceModel>
</weblog>
<weblog_mysql4>
<class>Magentotutorial_Weblog_Model_Mysql4</class>
</weblog_mysql4>
</models>
</config>
And my database name is blog_posts. Thanks in advance!
As per my previous comment, you need the mysql4 model class to have the class “talk” to the DB throught the Magento DB Abstraction Layer.
The issue with your model instantiation should be due to the missing tag in your config file:
Please let me know if this solves your problem.