I am a little confused here I didn't understand what is this.

I have a .phtml file in which there is a function say $this->getArticle() when I print this it show the array of the data's stored in the database.

Then I have a function call like this $this->getArticle()->getId(), $this->getArticle()->getContentHtml() these shows the values which is inside the array as the under the same name as database field i.e id and content_html.

I understand till now.

But in the next line there is another function call like this $this->getArticle()->getCategories() It is returning the categories inside the my article array. But what I didn't understand is that from where is this getArticle() calls the value. I dont have categories as an database field name.

In my class file I have a function defined as function getArticle() but there is no function named as getCategories.

Then I checked my model file and there I find the function getCategories which is actually returning the category values.

So the question is that, in the first two statement the the function is called from the class file while in the last one the same function getArticleis calling the model file and the next is the function in this file. how is this happen.

What is the logic behind this I didn't understand the flow here when to get value from model and when from class.

  • What is the class you are extending in Model?
    – Sukeshini
    Commented Feb 21, 2014 at 10:57
  • Mage_Core_Model_Abstract my model extends this class
    – Waseem
    Commented Feb 21, 2014 at 11:03

1 Answer 1


When you call $this inside a template file (one that has .phtml extenision) you are referring to the block of that template file.

So getArticle() probably returns an object of type Article and that object has a getCategories() method.

This is called fluent interface(http://tournasdimitrios1.wordpress.com/2011/04/11/the-basics-of-fluent-interfaces-in-php/)

  • and what if we use $this in the block file, then $this is referring to what.
    – Waseem
    Commented Feb 21, 2014 at 11:07
  • As you mentioned getArticle() return a model of type article. Now that model has a getCategories() method. Take a look at this magento.stackexchange.com/questions/4170/… Commented Feb 21, 2014 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.