0

ページの Mage_Core_Block_Text ブロックを介して文字列を追加しようとしています。ここに私のファイルがあります:

パッケージ レイアウト XML 更新ファイル local.xml は次のとおりです (他のすべてのハンドルがパッケージ レイアウト XML に適用された後に最後に呼び出されます)。

/var/www/magpractice/app/design/frontend/practice/default/layout/local.xml

<?xml version="1.0"?>
<layout version="0.1.0">
  <helloworld_index_index>
    <reference name="content">
      <block type="core/text" name="our_message">
        <action method="setText"><text>Hello Mars</text></action>
      </block>
    </reference>
  </helloworld_index_index>
</layout>

派生コントローラーは次のとおりです。

/var/www/magpractice/app/code/local/Alanstormdotcom/Helloworld/controllers/IndexController.php

class Alanstormdotcom_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {

  public function indexAction() {

  }

}

そして、ここに私のモジュールからの私の config.xml があります:

/var/www/magpractice/app/code/local/Alanstormdotcom/Helloworld/etc/config.xml

<config>
  <modules>
    <Alanstormdotcom_Helloworld>
      <version>0.1.0</version>
    </Alanstormdotcom_Helloworld>
  </modules>
  <global>
    <blocks>
        <helloworld>
            <class>Alanstormdotcom_Helloworld_Block</class>
        </helloworld>
    </blocks>
  </global>
  <frontend>
    <routers>
      <helloworld>
        <use>standard</use>
        <args>
          <module>Alanstormdotcom_Helloworld</module>
          <frontName>helloworld</frontName>
        </args>
      </helloworld>
    </routers>
  </frontend>
</config>

私が集めたものに関する限り、この例では Block ディレクトリの下に特別なブロックを指定する必要はありません。

http://localhost/magpractice/helloworld/index/index にアクセスすると、空白のページが表示されます。

... を ... に置き換えても同じです。

なんで?私は何が欠けていますか?

ありがとう。

4

1 に答える 1

1

メソッドにとindexActionの呼び出しがないようです。loadLayoutrenderLayout

$this->loadLayout();
$this->renderLayout();

このloadLayoutメソッドは XML を解析し、ブロック オブジェクトをインスタンス化します。

メソッドは、ルート ブロックでメソッドをrenderLayout呼び出します。toHtml

また、コントローラ アクションに a をドロップしvar_dump(__METHOD__);て、実際に呼び出されていることを確認すると便利です (空白のページとは異なり、非常に多くの異なることを意味する可能性があります)。

于 2013-06-17T19:07:25.753 に答える