1

これが私の config.xml です $blogpost を表示すると、何も表示されません。モデルがデータベースのデータを返さない理由がわかりません。次のエラーが表示されます。

致命的なエラー: オブジェクト以外でのメンバー関数 load() の呼び出し

<global>    
<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>
        <resourceModel>weblog_resource</resourceModel>
    </weblog>

    <weblog_resource>
        <class>Magentotutorial_Weblog_Model_Resource</class>
    </weblog_resource>
</models>

コントローラ

<?php

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

1 に答える 1

3

app/code/local/Magentotutorial/Weblog/etc/config.xml の以下のコードを置き換えます

<weblog_resource>
        <class>Magentotutorial_Weblog_Model_Resource</class>
</weblog_resource>

<weblog_resource>
         <class>Magentotutorial_Weblog_Model_Resource</class>
            <entities>
                <blogpost>
                    <table>blog_posts</table>
                </blogpost>
            </entities>
    </weblog_resource>

app/code/local/Magentotutorial/Weblog/Model/Resource/ に Blogpost.php を作成します。

以下のコードを Blogpost.php ファイルに入れます

<?php
class Magentotutorial_Weblog_Model_Resource_Blogpost extends Mage_Core_Model_Resource_Db_Abstract{
    protected function _construct()
    {
        $this->_init('weblog/blogpost', 'blogpost_id');
    }
}

コードを実行します..

詳細については :-ここをクリック

于 2014-07-11T07:44:50.737 に答える