Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Magento get method which loads Model, Block and Helper.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 411
    Comment on it

    In magento the functions that is mostly responsible for the things to be done are get and set methods, which are actually same as getter and setter methods.
    With the help of the get method we can actually call any model, block or helper.

     

    A simple direction to get the class files in magento:-

     

    1. Model call

     

    If we need to call any model in our case  'catalog/product' to get the products we can do it as  

    $_product = Mage::getModel('catalog/product')

    The class file of the above code is at:-

     

        app\code\core\Mage\Catalog\Model\Product.php

     

    Here we give only the module name and the model name as 'module\model' in the function getModel(). Then the magento append the whole path of that module's model name by appending 'Mage\' after that module name as 'Catalog\' then 'Model\' and in the end append the model file name with .php extention as '\Product.php' .
    This way the whole path of the model is fetched to call as 'Mage\Catalog\Model\Product.php'.

     

    2. Helper call

     

    Similarly, To call helper

    For helper file,

    $_helper = Mage::helper('catalog/output');

    The above helper file is at:-

     

        app\code\core\Mage\Catalog\Helper\Output.php

     

    In helpers we can call them without using the get method too.  Here we give only the module name and the helper name as 'module\helper' in the function helper() and then magento appends the whole path of the helper  as done in model.

     

    3. Block call

     

    Similarly, To load the Block class

    For Block file,

    $_block = Mage::getBlock('catalog/output');

    The above block file is at:-

     

        app\code\core\Mage\Catalog\Helper\Output.php

     

    In Block,  Here we give only the module name and the Block name as 'module\Block' in the function getBlock() and then magento appends the whole path of the Block as done in model.

     

    Now if we need to load the collections in magento the get method is helpful here.
    we can load the collection as :

    $_productCollection = Mage::getResourceModel('catalog/product_collection')
    
    or
    
    $_product = Mage::getModel('catalog/product')
    $_productCollection = $_product->getCollection();
    

    The above code is calling the collection class which is at the path app\code\core\Mage\Catalog\Model\Resource\Eav\Mysql4\Product\Collection.php.
    This will load the collection of the array of products.

     
     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: