0

I try to read the flow of magento but can not find the function

getCustomRootTemplate

that called line 102 of file app/code/core/mage/cms/helper/page.php

4
$page->getCustomRootTemplate()

it gets data from database you can check from database table cms_page

enter image description here

EDIT

It use magento magic magic method.

Magic Methods inside Magento are methods that are called to check, retrieve, set, or unset data. So, basically, you can fetch any data from the protected $_data array in an object simply by calling an appropriate Magic Method.

How it works is basically through the use of the Varien_Object class. Inside this class, it utilizes the __call() method as a last resort whenever it cannot find a method you called. The details look like this:

class Varien_Object located in lib/Varien/Object.php

/**
  * Set/Get attribute wrapper
  *
  * @param   string $method
  * @param   array $args
  * @return  mixed
  */
 public function __call($method, $args)
 {
     switch (substr($method, 0, 3)) {
         case 'get' :
             //Varien_Profiler::start('GETTER: '.get_class($this).'::'.$method);
             $key = $this->_underscore(substr($method,3));
             $data = $this->getData($key, isset($args[0]) ? $args[0] : null);
             //Varien_Profiler::stop('GETTER: '.get_class($this).'::'.$method);
             return $data;
         case 'set' :
             //Varien_Profiler::start('SETTER: '.get_class($this).'::'.$method);
             $key = $this->_underscore(substr($method,3));
             $result = $this->setData($key, isset($args[0]) ? $args[0] : null);
             //Varien_Profiler::stop('SETTER: '.get_class($this).'::'.$method);
             return $result;
         case 'uns' :
             //Varien_Profiler::start('UNS: '.get_class($this).'::'.$method);
             $key = $this->_underscore(substr($method,3));
             $result = $this->unsetData($key);
             //Varien_Profiler::stop('UNS: '.get_class($this).'::'.$method);
             return $result;
         case 'has' :
             //Varien_Profiler::start('HAS: '.get_class($this).'::'.$method);
             $key = $this->_underscore(substr($method,3));
             //Varien_Profiler::stop('HAS: '.get_class($this).'::'.$method);
             return isset($this->_data[$key]);
     }
     throw new Varien_Exception("Invalid method ".get_class($this)."::".$method."(".print_r($args,1).")");
 }

Every Model in Magento basically derives from this class so you can use magic methods (just about) anywhere.

Let’s take a simple example. You are fetching a product name within a class. You call the method:

$this->getName();

What Magento (or PHP for that matter) does is looks for a method called getName(). Simple enough. When it cannot find it, it looks up through it’s parent classes until it simply cannot find getName() anywhere. When it reaches this point, it goes through it’s last resort, the __call() method. Basically it passes the method and it’s arguments to the __call() method.

Let me know if you have any query

0

This function is simply a Magic function.

There is no concrete definition but it works because Magento will allow you to simply set and get data against a model.

It will end up using the setData and getData methods on the Varien_Object class.

  • What is Magic function used ? $page is instance of Mage_Cms_Model_Page, when try to call non-exist function from class, the magic function will be called, but i can not find the magic function in this class and parent of this class – Chameron May 5 '15 at 8:08
  • @Chameron see my edited answer – Keyur Shah May 5 '15 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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