Magento Expert Forum - Improve your Magento experience
-
Moderator
Using $this in magento programming
The infamous $this found in Magento templates is a concept that I’ve found baffles beginner Magento developers. Here’s to hoping I can provide a half-decent explanation as to what it is, and where it comes from.
The most important point you should take away from this is: all Magento templates have a corresponding block instance. The $this exposed to us is the block instance, as if we were inside a method of the object (We actually are! See Mage_Core_Block_Template::fetchView).
Blocks are PHP classes that are designed as a place to put all of your business logic, instead of your templates. Blocks are normally reusable classes. A great example of the reusability of certain classes is the Mage_Core_Block_Template and Mage_Page_Block_Html_Pager classes. The core/template block is the foundation of the template system, allowing us the ability to load .phtml files from our themes. The page/html_pager block provides generic methods for paginating collections, such as isLastPage().
If you’re ever in any doubt as to which block type the template is using, just call echo get_class($this). Remember, it’s an object. This gives you a great place to start when hunting down methods available to the template.
View more threads in the same category:
-
-
Magento is an Ecommerce Platform Created On Open Source Technology, which provides online merchants with an exceptional flexibility and control over the content, look and functionality of their e-commerce store.
-
-
What is Magento? It's the most powerful online eCommerce platform in the universe and is changing the face of eCommerce forever. :-)
Of course, you already know that. What you may not realize is Magento's also an object-oriented PHP Framework that can be used to develop modern, dynamic web applications that tap into Magento's powerful eCommerce features.
This is the first in a series of articles in which we're going to go on a whirlwind tour of Magento's programming framework features
-
-
nice
-
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks