magento 2column-right 模板 $this 也指哪里?
在 template.phtml 文件中有一行代码引用内容,使用 getChildHtml('内容') ?>; 它回显内容和包含的 div,我希望访问这个原始代码,以便我可以插入 一些自定义数据,但我怎么也找不到它在哪里?!我在核心中找到了 Mage_Page_Block_Html 类,但看不到它抛出的任何 html!
提前致谢
in the template.phtml file there is a line of code which refers to the content, using
getChildHtml('content') ?>
which echos out the content and the containing divs, i wish to access this raw code so i can insert
some custom data but for the life of me cannot find where it is?! i have found the Mage_Page_Block_Html class in the core but cannot see any html that it is throwing out!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在管理中,如果您转到系统>配置>高级>开发人员并从范围选择器(左上角)中选择您的商店视图,则可以打开模板和块提示。这将准确地告诉您哪个 PHP 块正在生成代码,因此
$this
与之相关。一般来说,所有基本布局模板都由
Mage_Core_Block_Template
支持,并且所有块都继承自Mage_Core_Block_Abstract
。干杯,
乔纳森
In the Admin, if you go to System>Config>Advanced>Developer and select your Store View from the Scope Selector (top-left), you can turn on Template and Block hints. That will tell you exactly which PHP Block is generating the code and therefore
$this
relates to.Generally, all the basic layout templates are backed by
Mage_Core_Block_Template
, and all blocks inherit fromMage_Core_Block_Abstract
.Cheers,
Jonathan
与往常一样,我建议了解整个布局系统正在做什么来了解正在发生的事情。
至于您的具体问题,
$this
始终引用模板的 Block 类。 (在 Magento 中每个 phtml 模板都有一个 Block 类)。这是哪个类取决于您的布局 XML 文件中的内容。您始终可以在运行时使用类似这样的内容输出类var_dump(get_class($this));
getChildHtml 方法是在基础抽象块类
app/code/core/Mage/Core/Block/Abstract.php
上定义的。该方法由所有块使用,因此请务必考虑到这一点你的代码。
As always, I recommend understanding what the entire layout system is doing to understand what's going on.
As to your specific question,
$this
always refers to the template's Block class. (Every phtml template has a Block class in Magento). Which class this is will depend on what's in your layout XML files. You can always output the class at runtime with something like thisvar_dump(get_class($this));
The
getChildHtml
method is defined on the base abstract block classapp/code/core/Mage/Core/Block/Abstract.php
This method is used by ALL blocks, so be sure you take this into account with your code.
作为旁注..如果您想知道 $this 指向哪里,您也可以使用
帮助我安静几次
as a side note.. if you ever wondering where a $this is point to you can also use
helped me out quiet a few times