1

私は、magento でモデルを呼び出して使用する方法を理解しようとしています。

私の現在のタスクは、コントローラーから呼び出して、モデルに保持されている文字列を単純に表示することです。

SimpleOutput.php を呼び出そうとすると、非オブジェクトが呼び出されたというエラー メッセージが表示されます。ご覧のとおり、var_dumped したところ、false が返されます。

私は自分のコードを調べましたが、Magento で何をする必要があるかについての理解が限られているため、すべてが正しいです。明らかに私は何かが欠けています。誰かが見て、それがタイプミスである場合はどこを見ればよいか、単純なスペルミス以上のものである場合は、何を見逃したのか、何をすべきだったのか、そしてその理由を説明してもらえますか?

私のコードは以下です

Ts/Firstmodule/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Ts_Firstmodule>
        <version>0.1.0</version>
    </Ts_Firstmodule>
</modules>

<models>
    <firstmodule>
        <class>Ts_Firstmodule_Model</class>
    </firstmodule>
</models>

<frontend>
    <routers>
        <firstmodule>
            <use>standard</use>
            <args>
                <module>Ts_Firstmodule</module>
                <frontName>firstmodule</frontName>
            </args>
        </firstmodule>
    </routers>
</frontend>
</config>

Ts/Firstmodule/controllers/indexController.php

class Ts_Firstmodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
    $simple = Mage::getModel('ts_firstmodule/simpleoutput');
    var_dump($simple);
}
}

Ts/Firstmodule/モデル/simpleoutput.php

class Ts_Firstmodule_Model_SimpleOutput extends Mage_Core_Model_Abstract
{
public function basicText()
{
    echo 'this is some text from the simple output model inside the basic text function';
}
}
4

3 に答える 3

0

いつものように:

Mage::getModel('ts_firstmodule/simpleoutput');

getModel / getBlock / helper / などを実行すると

パラメータ文字列の最初の部分は、config.xml で定義されたレイヤの XML ノードです。2 番目の部分は、レイヤ フォルダ コンテナからファイルへのフル パスです。

したがって、あなたの場合: Mage::getModel('firstmodule/simpleoutput'); ロードする必要がありますTs/Firstmodule/Model/Simpleoutput.php

注:リソースの大文字と小文字に注意してください(優れたプラクティスについては、標準のマジェントをご覧ください)!

于 2013-07-11T08:47:05.900 に答える