我是新来Magento的。在他们的文档教程中,有些问题让我抓狂。1、如何打开magento 1.5.1的开发模式?
2,“致命错误:在第7行的D:\PHPWeb\mag\app\code\local\Magentotutorial\Weblog\controllers\IndexController.php中对非对象调用成员函数load()”
这意味着我不能实例化一个模型对象。谁来帮帮我。下面是我的代码。
控制器:
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);
}
} 型号:
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>我的数据库名是blog_posts。提前感谢!
发布于 2011-07-14 16:54:51
根据我之前的评论,您需要mysql4模型类通过Magento DB抽象层与DB进行“对话”。
模型实例化的问题应该是由于配置文件中缺少标记造成的:
<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>
<global>
<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>
</global>
</config>如果这解决了你的问题,请让我知道。
发布于 2011-07-15 18:17:23
我在Magento 1.5上也遇到了同样的问题。对于开发者模式,请转到app/code/core/Mage.php,在第116行附近,将$_isDevelopperMode设置为true。您还需要删除第70行#ini_set上的index.php中的注释(‘display_errors’,1);
https://stackoverflow.com/questions/6690355
复制相似问题