2012-06-13 102 views
0

我是Magento的新手,我開始學習爲前端開發自定義模塊。我遵循了幾個指南,出於某種原因,他們都沒有工作。看起來好像loadLayout和renderLayout正在導致問題。我不知道這是因爲我在錯誤的位置有一個文件,或者是什麼問題。我已經嘗試加載頁面magento.x/helloworld magento.x/helloworld/index magento.x/index.php/helloworld。我收到了默認網站的損壞版本。如果我用echo來替換lLayout和rLayout,它就可以工作。這是我有:無法在Magento中創建自定義模塊

應用程序/代碼/本地/ Wrapids /的Helloworld的/ etc/config.xml中

<config> 
<modules> 
    <Wrapids_Helloworld> 
     <version>0.1.0</version> 
    </Wrapids_Helloworld> 
</modules> 
<frontend> 
    <routers> 
     <helloworld> 
      <use>standard</use> 
      <args> 
       <module>Wrapids_Helloworld</module> 
       <frontName>helloworld</frontName> 
      </args> 
     </helloworld> 
    </routers> 
    <layout> 
     <updates> 
      <helloworld> 
       <file>helloworld.xml</file> 
      </helloworld> 
     </updates> 
    </layout> 
</frontend> 
</config> 

應用程序/代碼/本地/ Wrapids /的Helloworld /控制器/ IndexController.php

<?php 
class Wrapids_Helloworld_IndexController extends Mage_Core_Controller_Front_Action 
    { 
    public function indexAction() 
    { 
     $this->loadLayout(); 
     $this->renderLayout(); 
    } 
    } 
?> 

/app/design/frontend/default/default/template/helloworld/page.phtml

text 

應用程序/設計/前端/默認/日故障/佈局/ helloworld.xml

<?xml version="1.0" encoding="UTF-8"?> 
<layout version="0.1.0"> 
    <default> 
     <reference name="content"> 
      <block type="helloworld/helloworld" name="hello" template="helloworld/page.phtml"> 
     </reference> 
    </default> 
</layout> 

應用程序/代碼/本地/ Wrapids /的Helloworld /座/ Helloworld.php

<?php 
    class Wrapids_Helloworld_Block_Helloworld extends Mage_Core_Block_Template 
    { 
    } 
?> 
+0

您的佈局XML結束標記(應用程序/設計/前端/預設/默認/佈局/ helloworld.xml )壞了,檢查是否是這個問題。 –

+0

哎呀,不。當我在這裏輸入時,輸入錯字。 – Sturm

+0

佈局文件存在問題。首先,你刪除根節點,據我記得它是主節點。我在佈局中看不到。 –

回答

2

我不太明白你的目標,但你可以試試:
應用程序/設計/前端/預設/默認/佈局/ helloworld.xml

<layout version="0.1.0"> 
    <default> 
     <reference name="root"> 
      <action method="setTemplate"><template>helloworld/page.phtml</template></action> 
     </reference> 
    </default> 
</layout> 
+0

你能解釋一下這個作品,而使用不? – Sturm

+0

想要用 diNord

+0

到目前爲止,任何類型的改變並不重要,沒有任何使用type =「」的東西到目前爲止工作。只有上面的方法與 Sturm

0

你有沒有加入Wrapids_Helloworld.xml文件到應用的/ etc /模塊,下面的代碼?這必須存在,以加載模塊

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Wrapids_Helloworld> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Wrapids_Helloworld> 
    </modules> 
</config> 
+0

是的,我在帖子中提到它使用echo,我不覺得我需要添加該代碼。 – Sturm

+1

我將這些文件複製到我的本地magento安裝(企業版)之一,並刪除根塊導致的問題。刪除頁腳顯示頁面沒有頁腳。看起來一切正常。要定義我使用''並在''裏面的動作。在'/ helloworld/index/index'中,我看到沒有頁腳的頁面。 – Zefiryn

1

移動模板和佈局文件[your_package] /默認或[your_package]/[your_theme]