23.02.2015 Views

www.it-ebooks.info

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Magento Fundamentals for Developers<br />

Let's review each folder in more detail:<br />

• Block: This folder contains blocks in Magento that form an add<strong>it</strong>ional layer<br />

of logic between the controllers and views<br />

• controllers: controllers folders are formed by actions that process web<br />

server requests<br />

• Controller: The classes in this folder are meant to be abstract classes and<br />

extended by the controller class under the the controllers folder<br />

• etc: Here we can find the module-specific configuration in the form of XML<br />

files such as config.xml and system.xml<br />

• Helper: This folder contains auxiliary classes that encapsulate a<br />

common-module functional<strong>it</strong>y and make <strong>it</strong> available to a class of<br />

the same module and to other modules' classes as well<br />

• Model: This folder contains models that support the controllers in the module<br />

for interacting w<strong>it</strong>h data<br />

• sql: This folder contains the installation and upgrade files for each<br />

specific module<br />

As we will see later on in this chapter, Magento makes heavy use of factory names<br />

and factory methods. This is why the folder structure is so important.<br />

Modular arch<strong>it</strong>ecture<br />

Rather than being a large application, Magento is built by smaller modules, each<br />

adding specific functional<strong>it</strong>y to Magento.<br />

One of the advantages of this approach is the abil<strong>it</strong>y to enable and disable<br />

specific module functional<strong>it</strong>y w<strong>it</strong>h ease, as well as add new functional<strong>it</strong>y by<br />

adding new modules.<br />

Autoloader<br />

Magento is a huge framework, composed of close to 30,000 files. Requiring every<br />

single file when the application starts would make <strong>it</strong> incredibly slow and heavy. For<br />

this reason, Magento makes use of an autoloader class to find the required files each<br />

time a factory method is called.<br />

So, what exactly is an autoloader? PHP5 includes a function called __autoload().<br />

When instantiating a class, the __autoload() function is automatically called; inside<br />

this function, custom logic is defined to parse the class name and the required file.<br />

[ 30 ]<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!