I have gone through various Magento tutorials as well as a Magento book on layout, but I'm stuck with the following problem.
我已经阅读了各种Magento教程以及关于布局的Magento书籍,但我遇到了以下问题。
I have created a custom module, located in app/code/local/Company/Module/ . I have created a block Company_Module_Block_Ablock located in Company/Module/Block/Ablock.php. I have defined <config> ... <frontend><layout><updates><module><file>module.xml
in Company/Module/etc/config.xml
我创建了一个自定义模块,位于app / code / local / Company / Module /中。我创建了一个位于Company / Module / Block / Ablock.php中的块Company_Module_Block_Ablock。我在Company / Module / etc / config.xml中定义了
config.xml also has
config.xml也有
<global>
<blocks>
<module>
<class>Company_Module_Block</class>
</module>
</blocks>
</global>
Inside this module.xml I have:
在这个module.xml里面我有:
<layout>
<company_module_index_index>
<reference name="content">
<block type="module/ablock" name="myablock" template="module/ablock.phtml" />
</reference>
</company_module_index_index>
</layout>
I have created a Company/Module/controllers/IndexController.php and have a indexAction defined there which does
我创建了一个Company / Module / controllers / IndexController.php并在那里定义了一个indexAction
$this->loadLayout();
$this->renderLayout();
But whatever I try I'm unable to get my ablock.phtml to display. ablock.phtml is in app/design/frontend/company/default/template/module/ablock.phtml. The theme has been enabled and is generally working on the site.
但无论我尝试什么,我都无法显示我的ablock.phtml。 ablock.phtml位于app / design / frontend / company / default / template / module / ablock.phtml中。该主题已启用,通常在该网站上工作。
I have even tried to change module.xml inside layout so its not even using a template and even this is not displaying anything. Like this -
我甚至尝试在布局中更改module.xml,因此它甚至没有使用模板,甚至没有显示任何内容。喜欢这个 -
<reference name="content">
<block type="core/text">
<action method="setText">
<text>Testing</text>
</action>
</block>
</reference>
By the way the custom theme works fine otherwise, other pages have content displayed in them in the correct place.
顺便说一句,自定义主题工作正常,其他页面的内容显示在正确的位置。
I have SetEnv MAGE IS DEVELOPER MODE 1
in .htaccess which is supposed to help display even warnings and things. But my systems.log and exceptions.log have no errors in them. (Yes logging is turned on)
我在.htaccess中有SetEnv MAGE IS DEVELOPER MODE 1,它可以帮助显示警告和事物。但是我的systems.log和exceptions.log中没有错误。 (是的日志记录已打开)
Anyone have any advise on how to troubleshoot this or can spot a mistake in the configuration or code?
任何人都有任何建议如何解决这个问题或者可以发现配置或代码中的错误?
My next option seems to be hacking the core module code and logging where my module.xml is being loaded and parsed to see what is going on there.
我的下一个选择似乎是破解核心模块代码并记录我的module.xml被加载和解析的位置以查看那里发生了什么。
Thanks.
谢谢。
3 个解决方案
#1
31
Steps to Debug Layout Update XML issues:
调试布局更新XML问题的步骤:
-
Is your XML file (
local.xml
ormodule.xml
) being loaded into the system您的XML文件(local.xml或module.xml)是否已加载到系统中
-
Does the handle tag you used in your layout file match a handle being generated for your request?
您在布局文件中使用的句柄标记是否与为您的请求生成的句柄相匹配?
The quickest way to debug step 1 is, while in developer mode with errors showing, deliberately introduce a non-well-formed error to your Layout Update XML file.
调试步骤1的最快方法是,在显示错误的开发人员模式下,故意向Layout Update XML文件中引入一个格式错误的错误。
<layout <!-- notice missing closing taglayout -->
<company_module_index_index>
<reference name="content">
<block type="module/ablock" name="myablock" template="module/ablock.phtml" />
</reference>
</company_module_index_index>
</layout>
If developer mode is on and you've cleared your cache, loading any page with the above in place will cause an error. This lets you know that Magento is trying to load your XML file. If the page loads without problem, that means you have your XML file in the wrong location, or you've misconfigured your XML in config.xml
.
如果启用了开发人员模式并且您已清除缓存,则加载具有上述内容的任何页面都将导致错误。这让您知道Magento正在尝试加载您的XML文件。如果页面加载没有问题,这意味着您将XML文件放在错误的位置,或者您在config.xml中错误配置了XML。
Next up is your checking your layout handle. You'll want to make sure you're using the right one. You can view the layout handles that were used for a particular request by calling the following after your loadLayout
and renderLayout
request
接下来是你检查你的布局句柄。你需要确保使用正确的。您可以通过在loadLayout和renderLayout请求后调用以下内容来查看用于特定请求的布局句柄
//from a controller action
$this->loadLayout();
$this->renderLayout();
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
exit("bailing early at ".__LINE__." in ".__FILE__);
I've found the above items usually take care of 90% of layout problems. Be sure to go through the process a few times, as it's easy to miss one step and assume something's all right when it's not. Taking my usual risk of being a shill, part of why I created Commerce Bug (commercial debugging extension) was to provide this information quickly, and at a glance, to help with debugging problems.
我发现上面的项目通常会处理90%的布局问题。一定要经历几次这个过程,因为它很容易错过一步,并且当它不是时就会假设一切正常。我常常冒这个风险,我创建Commerce Bug(商业调试扩展)的部分原因是为了快速提供这些信息,并一目了然地帮助调试问题。
Based on your comments below, the problem appears to be the layout handle you're using. The handle that's generated by the system is
根据您在下面的评论,问题似乎是您正在使用的布局句柄。系统生成的句柄是
module_module_test
However, the handle you're defining in your layout.xml is
但是,您在layout.xml中定义的句柄是
company_module_index_index
This is the "full action name" handle. The typical syntax for this is
这是“完整操作名称”句柄。典型的语法是
frontname_controllername_actionname
Change the handle to module_module_test
and you should be set.
将句柄更改为module_module_test,您应该设置。
#2
1
- did you disable or update Magento cache?
- 你禁用或更新Magento缓存了吗?
- is your module enabled? Is it listed in System, Configuration, Advanced, Advanced?
- 是你的模块启用了吗?它是否列在系统,配置,高级,高级?
- which class does your Block extend?
- 你的Block扩展了哪个类?
Regards, Alessandro
此致,亚历山德罗
#3
0
I cannot tell without seeing all of your config.xml, you might be missing a section like this:
我看不到你所有的config.xml,你可能会错过这样一个部分:
<frontend>
<routers>
<company_module>
<args>
<frontName>module</frontName>
<module>Company_Module</module>
</args>
<use>standard</use>
</company_module>
</routers>
</frontend>
Then, to reach the indexAction
or your indexController
you would need the address www.example.com/module
. That will mean the layout handle company_module_index_index
is used when you load the layout. BTW, the posted layout XML is broken, the closing tag does not match the opening tag.
然后,要访问indexAction或indexController,您需要地址www.example.com/module。这将意味着在加载布局时使用布局句柄company_module_index_index。顺便说一句,发布的布局XML被破坏,结束标记与开始标记不匹配。
#1
31
Steps to Debug Layout Update XML issues:
调试布局更新XML问题的步骤:
-
Is your XML file (
local.xml
ormodule.xml
) being loaded into the system您的XML文件(local.xml或module.xml)是否已加载到系统中
-
Does the handle tag you used in your layout file match a handle being generated for your request?
您在布局文件中使用的句柄标记是否与为您的请求生成的句柄相匹配?
The quickest way to debug step 1 is, while in developer mode with errors showing, deliberately introduce a non-well-formed error to your Layout Update XML file.
调试步骤1的最快方法是,在显示错误的开发人员模式下,故意向Layout Update XML文件中引入一个格式错误的错误。
<layout <!-- notice missing closing taglayout -->
<company_module_index_index>
<reference name="content">
<block type="module/ablock" name="myablock" template="module/ablock.phtml" />
</reference>
</company_module_index_index>
</layout>
If developer mode is on and you've cleared your cache, loading any page with the above in place will cause an error. This lets you know that Magento is trying to load your XML file. If the page loads without problem, that means you have your XML file in the wrong location, or you've misconfigured your XML in config.xml
.
如果启用了开发人员模式并且您已清除缓存,则加载具有上述内容的任何页面都将导致错误。这让您知道Magento正在尝试加载您的XML文件。如果页面加载没有问题,这意味着您将XML文件放在错误的位置,或者您在config.xml中错误配置了XML。
Next up is your checking your layout handle. You'll want to make sure you're using the right one. You can view the layout handles that were used for a particular request by calling the following after your loadLayout
and renderLayout
request
接下来是你检查你的布局句柄。你需要确保使用正确的。您可以通过在loadLayout和renderLayout请求后调用以下内容来查看用于特定请求的布局句柄
//from a controller action
$this->loadLayout();
$this->renderLayout();
var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
exit("bailing early at ".__LINE__." in ".__FILE__);
I've found the above items usually take care of 90% of layout problems. Be sure to go through the process a few times, as it's easy to miss one step and assume something's all right when it's not. Taking my usual risk of being a shill, part of why I created Commerce Bug (commercial debugging extension) was to provide this information quickly, and at a glance, to help with debugging problems.
我发现上面的项目通常会处理90%的布局问题。一定要经历几次这个过程,因为它很容易错过一步,并且当它不是时就会假设一切正常。我常常冒这个风险,我创建Commerce Bug(商业调试扩展)的部分原因是为了快速提供这些信息,并一目了然地帮助调试问题。
Based on your comments below, the problem appears to be the layout handle you're using. The handle that's generated by the system is
根据您在下面的评论,问题似乎是您正在使用的布局句柄。系统生成的句柄是
module_module_test
However, the handle you're defining in your layout.xml is
但是,您在layout.xml中定义的句柄是
company_module_index_index
This is the "full action name" handle. The typical syntax for this is
这是“完整操作名称”句柄。典型的语法是
frontname_controllername_actionname
Change the handle to module_module_test
and you should be set.
将句柄更改为module_module_test,您应该设置。
#2
1
- did you disable or update Magento cache?
- 你禁用或更新Magento缓存了吗?
- is your module enabled? Is it listed in System, Configuration, Advanced, Advanced?
- 是你的模块启用了吗?它是否列在系统,配置,高级,高级?
- which class does your Block extend?
- 你的Block扩展了哪个类?
Regards, Alessandro
此致,亚历山德罗
#3
0
I cannot tell without seeing all of your config.xml, you might be missing a section like this:
我看不到你所有的config.xml,你可能会错过这样一个部分:
<frontend>
<routers>
<company_module>
<args>
<frontName>module</frontName>
<module>Company_Module</module>
</args>
<use>standard</use>
</company_module>
</routers>
</frontend>
Then, to reach the indexAction
or your indexController
you would need the address www.example.com/module
. That will mean the layout handle company_module_index_index
is used when you load the layout. BTW, the posted layout XML is broken, the closing tag does not match the opening tag.
然后,要访问indexAction或indexController,您需要地址www.example.com/module。这将意味着在加载布局时使用布局句柄company_module_index_index。顺便说一句,发布的布局XML被破坏,结束标记与开始标记不匹配。