Thursday, May 20, 2010

how to find methods in Magento

Here is how I've learned.
Let's say you have in a phtml file this line of code.
($object can be anything including $this).
And you don't know what type is $object.
put this line above the method call.
echo get_class($object);
Clear the cache (contents of var/cache) and reload the page. You should see the name of the class. For example Mage_Catalog_Model_Category. now all you have to do is to find the class.
Because Magento is based on Zend Framework it uses the the same convention for class naming.
So class Abc_Def_Ghi will be in the file Abc/Def/Ghi.php (for the example above the file is Mage/Catalog/Model/Category.php)
All the classes are placed in app/code/core or app/code/local/ or app/code/community or lib/ and after that follow the path like explained above.

If you don't find a method in that specific class look in one of the parents. Check the class that the current class extends.

You will not find all the methods in Magento. For example some of the methods that start with get, set, has, uns is possible that the methods are missing.
For this take a look in Varien_Object class (that is the base class for most of the objects) lib/Varien/Object.php file (remember the convention above?) and look in the 'magic' method __call().

1 comment:

  1. I use a lot, just paste the class name in the search box. Unfortunately it is still stuck in ver