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.

Chapter 3<br />

In add<strong>it</strong>ion to that, each Model type is formed by the following layers:<br />

• Model class: Here is where most of our business logic resides. Models are<br />

used to manipulate the data, but they don't access <strong>it</strong> directly.<br />

• Resource Model class: Resource Models are used to interact w<strong>it</strong>h<br />

the database on behalf of our models. They are in charge of the actual<br />

CRUD operations.<br />

• Model Collection class: Each Data Model has a collection class; collections<br />

are objects that hold a number of individual Magento Model instances.<br />

CRUD stands for the four basic types of database operations:<br />

create, read, update, and delete.<br />

Magento Models don't contain any logic for communicating w<strong>it</strong>h the database; they<br />

are database agnostic. Instead, this code resides in the Resource Model layer.<br />

This gives Magento the capac<strong>it</strong>y to support different types of databases and<br />

platforms. Although currently only MySQL is officially supported, <strong>it</strong> is entirely<br />

possible to wr<strong>it</strong>e a new resource class for a new database w<strong>it</strong>hout touching any<br />

of the Model logic ones.<br />

Model Layer<br />

Model<br />

Resource Layer<br />

Resource Model<br />

Adapter Layer<br />

Database adapter<br />

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