23.02.2015 Views

www.it-ebooks.info

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Magento Fundamentals for Developers<br />

Configuration options in Magento can store values on three scopes (global, webs<strong>it</strong>e,<br />

and store view); by default, all the values are set on the global scope. By using<br />

system.xml on our modules, we can specify the scopes on which the configuration<br />

options can be set; let's revis<strong>it</strong> our previous system.xml:<br />

…<br />

<br />

Enabled<br />

<br />

HTML]]><br />

<br />

select<br />

adminhtml/system_config_source_yesno<br />

10<br />

1<br />

1<br />

1<br />

<br />

…<br />

Factory names and functions<br />

Magento makes use of factory methods to instantiate Model, Helper, and Block<br />

classes. A factory method is a design pattern that allows us to instantiate an object<br />

w<strong>it</strong>hout using the exact class name and using a class alias instead.<br />

Magento implements several factory methods, as follows:<br />

• Mage::getModel()<br />

• Mage::getResourceModel()<br />

• Mage::helper()<br />

• Mage::getSingleton()<br />

• Mage::getResourceSingleton()<br />

• Mage::getResourceHelper()<br />

Each of these methods takes a class alias that is used to determine the real class name<br />

of the object that we are trying to instantiate; for example, if we wanted to instantiate<br />

a product object, we can do so by calling the getModel() method:<br />

$product = Mage::getModel('catalog/product');<br />

[ 48 ]<br />

<strong>www</strong>.<strong>it</strong>-<strong>ebooks</strong>.<strong>info</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!