Magento 中的块和模板如何工作
我已经使用magento有一段时间了,有一些细节我试图了解它是如何工作的,块和模板,例如,我不明白如何工作的部分是你可以在template(一个 .phtml 文件)
$this->getFunctionName();
这意味着分配了该模板的块中有一个具有该名称的函数。
我试图写一个简单的例子只是为了看看它是如何工作的,但我无法弄清楚,直到现在,我只是头疼。
如何在 .phtml 文件中使用 $this 来调用块函数?似乎 .phtml 是对象的一部分,对吗?
谢谢
i've been working with magento for a while and there is some detail that i'm trying to understand how it works, block and templates, for example, the part i don't understand how works is that you can do this in a template( a .phtml file)
$this->getFunctionName();
this means that there is a function with that name in the block that was assigned that template.
I'm trying to write a simple example just to see how it works but i can't figure it out, untill now, i just have a headeach.
How is posible that you can use $this within a .phtml file to call the block functions?? Seems to be that the .phtml is part of the object, right?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 Mage_Core_Block_Template 的 fetchView 方法,模板文件包含在该方法中并且可以访问该类。输出缓冲用于收集模板输出,而不是显示模板所包含的内容。
Check out the fetchView method of Mage_Core_Block_Template, template files are included within that method and have access to the class. Output buffering is used to collect the template output, rather than displaying the template as it's included.
当文件在 PHP 中被
include
/require
时,在大多数情况下,您可以假设其中的代码被内联到调用文件中。因此,所有范围(包括$this
)都会被模板文件继承。When a file is
include
/require
'd in PHP, you can for most purposes suppose that the code inside of it gets inlined into the calling file. Hence, all scope (including$this
gets inherited by the template file.