Magento 中的块和模板如何工作

发布于 2024-10-19 23:13:10 字数 314 浏览 6 评论 0原文

我已经使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北风几吹夏 2024-10-26 23:13:10

查看 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.

下雨或天晴 2024-10-26 23:13:10

当文件在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文