简体   繁体   中英

How block and template work in Magento

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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