• No se han encontrado resultados

5. ESTUDIO TECNICO

5.8. ESTUDIO ADMINISTRATIVO

5.8.2. CAUSALES DE DISOLUCION

Updates are fragments of XML that are added to a layout object one at a time.

These fragments are then processed for special instructions and combined into

a Page Layout XML tree. The Page Layout XML tree (which we covered in the

first half of this chapter) then renders the page.

By allowing us to build Page Layouts using these chunks of XML, Magento

encourages splitting layouts up into logical components which can then be used

to build a variety of pages. If that was a bit abstract and hard the follow, our

code samples should clear things up.

We’ll rely on our trusty hello world block to lead the way. Add the following

action to our

UpdateController.php

file.

# h t t p : / / m a g e n t o . e x a m p l e . c o m / n o f r i l l s _ b o o k l a y o u t / u p d a t e / h e l l o U p d a t e s p u b l i c f u n c t i o n h e l l o U p d a t e s A c t i o n () { $ l a y o u t = M a g e :: g e t S i n g l e t o n ( ’ c o r e / l a y o u t ’ ); $ u p d a t e _ m a n a g e r = $layout - > g e t U p d a t e (); $ u p d a t e _ m a n a g e r - > a d d U p d a t e ( ’ < b l o c k t y p e =" n o f r i l l s _ b o o k l a y o u t / h e l l o w o r l d " n a m e =" r o o t " o u t p u t =" t o H t m l " / > ’ ); $layout - > g e n e r a t e X m l (); $layout - > g e n e r a t e B l o c k s (); e c h o $layout - > s e t D i r e c t O u t p u t ( t r u e ) - > g e t O u t p u t (); }

The three new lines we’re interested in above are

$ u p d a t e _ m a n a g e r = $layout - > g e t U p d a t e (); $ u p d a t e _ m a n a g e r - > a d d U p d a t e ( ’ < b l o c k t y p e =" n o f r i l l s _ b o o k l a y o u t / h e l l o w o r l d " n a m e =" r o o t " o u t p u t =" t o H t m l " / > ’ ); $layout - > g e n e r a t e X m l ();

These replace the manual loading of our page layout that we did above. First, a

Layout object contains a reference to a

Mage Core Model Layout Update

object. This

object is responsible for managing and holding the individual XML chunks that

we’re calling updates.

2.8.1

What’s a ”Model”

You may be wondering why both the Layout and this new Update Manager

objects are models, even though they don’t read/write to/from a database. If

you’ve used PHP based MVC systems in the past, you’ve probably become

accustomed to the idea that a

Model

is an object that represents a table of data

in a SQL database, or perhaps evenmultiple tables. While that’s become one

common understanding of the term, the original meaning of Model in MVC was

the computer science termDomain Model.

The Domain Model is an abstract concept. It’s where you describe the concepts

and vocabulary of the problems you’re trying to solve in code. It’s sometimes

referred to as business logic, or the objects that you use when writing business

logic code.

The ”Un-Domain Model” portions of a project are things like the code that runs

your controller dispatching, or the code that renders a template. This is code

you might use on any projects for any number of companies, each with their

own Domain Model.

Another way of thinking about this might be a school. Teachers, students,

classes, which classes are in each room; these things are all the Domain Model

of a School. The non Domain Model would then be the school building itself,

its plumbing and boiler, etc.

We mention this here because much of the Magento model layer can be thought

of in the more recent, ”Models are data in a database way”. The layout and

update hierarchy, however, cannot. A layout and an update object are both

models in the Domain Model sense of the word. They are modeling the ”busi-

ness rules” of creating HTML pages. This can be particularly confusing with

the update object, as a single update object will be used to manage multiple

Layout Update XML fragments. That’s why we’re calling this object an Update

Manager

Documento similar