简体   繁体   English

Magento:IndexController不会加载phtml文件

[英]Magento: IndexController doesn't load phtml file

As mentioned in the title I can't get my IndexController to load my view.phtml within it's index (or any other) action. 如标题中所述,我无法让IndexController在其index(或任何其他)操作中加载view.phtml。 Hopefully someone can help tell me what I'm doing wrong/missing. 希望有人可以告诉我我做错了/错过了什么。 Here is what I got: 这是我得到的:

app/etc/modules/ Namespace_MyModule.xml app / etc / modules / Namespace_MyModule.xml

<?xml version="1.0"?>

<config>
    <modules>
        <Namespace_MyModule>
            <active>true</active>
            <codePool>local</codePool>
        </Namespace_MyModule>
    </modules>
</config>

app/code/local/Namespace/MyModule/etc/ config.xml 应用程序/代码/本地/命名空间/ 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>

app/design/frontend/default/namespace/layout/ mymodule.xml 应用程序/设计/前端/默认/命名空间/布局/ 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>

app/code/local/Namespace/MyModule/controllers/ IndexController.php 应用程序/代码/本地/命名空间/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 app / design / frontend / default / namespace / template / mymodule / view.phtml

<h1><?php echo "What ever"; ?></h1>

You did a mistake in layout file. 您在布局文件中犯了一个错误。 You have specify the handle like 您已经指定了句柄

frontname_controller_action

So try this code 所以试试这段代码

<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>

Ok I got it fixed now. 好吧,现在我把它修复了。 Some may hate me for this but the problem was that my template wasn't loaded. 有些人可能为此而讨厌我,但问题是我的模板未加载。 I had to change settings in Magento admin area. 我不得不在Magento管理区域中更改设置。

General->Design->Themes->Templates->"Your Template" (In my case namespace) General->Design->Themes->Layout->"Your Template" (In my case namespace) 常规->设计->主题->模板->“您的模板”(以我的名字空间)常规->设计->主题->布局->“您的模板”(以我的名字空间)

or simply add it to 或直接将其添加到

General->Design->Themes->Default->"Your Template" (In my case namespace) 常规->设计->主题->默认->“您的模板”(在我的情况下是名称空间)

wich works the same way since Magento has a fallback system. 由于Magento具有后备系统,因此工作方式相同。

Now I'm wondering how to add custom phtml files without the need of putting them in the template folder you are currently using but thats another topic. 现在,我想知道如何添加自定义phtml文件,而无需将其放在您当前正在使用的模板文件夹中,但这是另一个主题。

Thanks Meenakshi Sundaram R for the help and thanks to everyone who took his time to read through all this. 感谢Meenakshi Sundaram R的帮助,也感谢所有花时间阅读所有内容的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM