3. 3
• Division into 3 main parts
of the application:
• Model - represents the
application logic
• View - describes how to
display data within the
user interface
• Controller - accepts input
from the user, updates the
model and refreshes the
view
MVC
5. MVC in MVC
The view layer in Magento itself
implements the MVC pattern.
M - blocks
V - templates.phtml
C – layouts (.xml files)
6. MVC in MVC
In xml files we define the blocks, which
are part of the view for a given controller
action and assign the appropriate
template to the main block
present the data obtained from the
block
load and render the layout
download data from the model layer, process it
and send to the template
8. 8
• Patterns orders grouping
of individual functions in
the project into modules
• Modules should not
require other modules for
proper operation
• Patterns define the
directory structure within
the parent module
directory
Modularity
9. 9
• Magento autoloader has
pre-established search
priorities
• Subdirectory structure is
not only a matter of
convention.
• Magento class name
reflects its path
• The individual components
of the Module must be
explicitly declared the
module configuration file
Modularity in Magento
code pools
Subdirectory structure
in the module’s main
directory
10. 1
A short digression - Autoloader
Code pools are added in a pre-
defined order
set up php of our path of attaching files
registering the autoloader
11. 1
A short digression - Autoloader
The autoloader is called upon class instantiation, unless there is already an object of a
given class in the memory - the file is already attached
note that this is not a built-in
implementation of __autoload () method
Attach the desired file
19. Registry
It allows you to place
objects and data in the global
pool, allowing access to them
from anywhere in the code
20. 2
Registry
If you call a method with graceful parameter set to true,
you can avoid the occurence of an exception informing
you that there is a value under the given key
if at a given index there is an object that has a
destructor, use it
23. 2
How can you add your own observer?
events node
name of the event
module name/class name
name of the calling method at
the event
unique observer ID
25. 2
Event/Observer
Object $area represents certain parts of
the application (frontend, global, admin,
adminhtml)
download the configuration of events for
each part of the application
iterate through all observers for a given
part of the application
Assign a taable of observers to a table of
events under the key of an event name
that they are observing
26. 2
Event/Observer
for each of the observers we try to call its
event operating procedures
assign the observer the
arguments transferred in the
event call
the function calling the observer’s method
call the method by transferring the observer’s
object with the arguments submitted earlier
28. Front controller
It is the entrance gate for all
requests directed at the
running applications..
It consists of two parts:
• web handler - parses the
URL and determines which
controller is to be created
• command dispatch -
creates a controller and
forwards the request
30. 3
The front controller is designed to
accept a request and decide what
to do with it. Does it all really
happen in the index.php file?
Is that so?
31. 3
What's under the hood?
What have we here?
Get front controller
Call
Call
32. 3
What's under the hood?
Iterate through router info table
containing the name of the router class
and its place of operation (frontend,
admin)
add the created router to the variable
_routers by the method addRouter (). We
will use them in the near future
also a default router is created and added
33. 3
What's under the hood?
Use the completed _routers table
We adapt the request to the router. Match is a
method of the abstract class
Mage_Core_Controller_Varien_Router_Abstract,
so each router defines its own body of this
method
In the match() method, check if the request matches
the address of the router and, if so, transfer the request
to the target module controller
Send an answer to the http client
35. Prototype
The Prototype pattern is a kind
of extension of the abstract
factory pattern. Since it hasn’t
been discussed, it will be briefly
described below
36. A short digression – abstract facory
It defines a set of factory classes that inherit
from the abstract parent class (factory), which
specialize in creating groups of objects from
one family.
38. Prototype
It is a variation of abstract
factory pattern
It helps to limit the number of
factories by creating a generic
factory which is sent the types
of objects to be produced
40. Prototyp w Magento
4
the facory method is called and
we transfer a product object as a
parameter
41. Prototyp w Magento
4
download type id transferred in the
product parameter
from the type table and corresponding names of
model classes we download the one correct for
our product
concretize object type of a product and set up the
product to operate on
42. There are more design
patterns in Magento, I
strongly encourage you
to explore them