![](/img/trans.png)
[英]Magento updateAttributes doesn't work in own modules IndexController
[英]Magento: IndexController doesn't load phtml file
如標題中所述,我無法讓IndexController在其index(或任何其他)操作中加載view.phtml。 希望有人可以告訴我我做錯了/錯過了什么。 這是我得到的:
app / etc / modules / Namespace_MyModule.xml
<?xml version="1.0"?>
<config>
<modules>
<Namespace_MyModule>
<active>true</active>
<codePool>local</codePool>
</Namespace_MyModule>
</modules>
</config>
應用程序/代碼/本地/命名空間/ MyModule / etc / config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Namespace_MyModule>
<version>0.3</version>
</Namespace_MyModule>
</modules>
<frontend>
<layout>
<updates>
<namespace_mymodule>
<file>mymodule.xml</file>
</namespace_mymodule>
</updates>
</layout>
<routers>
<namespace_mymodule>
<use>standard</use>
<args>
<module>Namespace_MyModule</module>
<frontName>something</frontName>
</args>
</namespace_mymodule>
</routers>
</frontend>
</config>
應用程序/設計/前端/默認/命名空間/布局/ mymodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<something_index_index>
<reference name="content">
<block type="core/template" name="namespace_mymodule_view" template="mymodule/view.phtml" />
</reference>
</something_index_index>
</layout>
應用程序/代碼/本地/命名空間/MyModule/controllers/IndexController.php
<?php
class Namespace_MyModule_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
app / design / frontend / default / namespace / template / mymodule / view.phtml
<h1><?php echo "What ever"; ?></h1>
您在布局文件中犯了一個錯誤。 您已經指定了句柄
frontname_controller_action
所以試試這段代碼
<layout version="0.1.0">
<something_index_index>
<reference name="content">
<block type="core/template" name="namespace_mymodule_view" template="mymodule/view.phtml" />
</reference>
</something_index_index>
</layout>
好吧,現在我把它修復了。 有些人可能為此而討厭我,但問題是我的模板未加載。 我不得不在Magento管理區域中更改設置。
常規->設計->主題->模板->“您的模板”(以我的名字空間)常規->設計->主題->布局->“您的模板”(以我的名字空間)
或直接將其添加到
常規->設計->主題->默認->“您的模板”(在我的情況下是名稱空間)
由於Magento具有后備系統,因此工作方式相同。
現在,我想知道如何添加自定義phtml文件,而無需將其放在您當前正在使用的模板文件夾中,但這是另一個主題。
感謝Meenakshi Sundaram R的幫助,也感謝所有花時間閱讀所有內容的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.