首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >阅读教程中的Magento基本问题

问阅读教程中的Magento基本问题
EN

Stack Overflow用户
提问于 2011-07-14 16:19:37
回答 2查看 406关注 0票数 3

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

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

这意味着我不能实例化一个模型对象。谁来帮帮我。下面是我的代码。

控制器:

代码语言:javascript
复制
    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);    
    } 
} 

型号:

代码语言:javascript
复制
class Magentotutorial_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract {
    protected function _construct() {
        $this->_init('weblog/blogpost');
    }
} 

Config.xml:

代码语言:javascript
复制
    <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。提前感谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-14 16:54:51

根据我之前的评论,您需要mysql4模型类通过Magento DB抽象层与DB进行“对话”。

模型实例化的问题应该是由于配置文件中缺少标记造成的:

代码语言:javascript
复制
<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>

如果这解决了你的问题,请让我知道。

票数 3
EN

Stack Overflow用户

发布于 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);

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6690355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档