Magento基本问题通过阅读教程

时间:2011-07-14 08:19:37

标签: magento

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

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

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

控制器:

    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。提前谢谢!

2 个答案:

答案 0 :(得分:3)

根据我之前的评论,你需要mysql4模型类让类通过Magento数据库抽象层与数据库“对话”。

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

<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>

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

答案 1 :(得分:0)

我和Magento 1.5有同样的问题。对于开发者模式,请转到app / code / core / Mage.php, 在第116行附近,将$ _isDevelopperMode设为true。您还需要删除第70行#ini_set('display_errors',1)中index.php中的注释;