gpt4 book ai didi

通过阅读教程了解 Magento 基本问题

转载 作者:行者123 更新时间:2023-12-01 22:25:29 26 4
gpt4 key购买 nike

我是 Magento 新手。他们文档的教程中的一些问题让我抓狂。1、如何在magento 1.5.1中打开开发模式?

2,“ fatal error :在第 7 行 D:\PHPWeb\mag\app\code\local\Magentotutorial\Weblog\controllers\IndexController.php 中的非对象上调用成员函数 load()”

这意味着我无法实例化模型对象。谁来帮帮我。这是我下面的代码。

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);
}
}

型号:

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

配置.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。提前致谢!

最佳答案

根据我之前的评论,您需要 mysql4 模型类让该类通过 Magento 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>

如果这能解决您的问题,请告诉我。

关于通过阅读教程了解 Magento 基本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6690355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com