Obsah
(this page is translated by Google; We're working hard on a human translation)
Glossary
Component, Control, Controller, snippet, presenter, model and module. What is the difference between them?
There is also a quick overview of the concepts .
Many beginning programmers with Nette has problems with possible differences of the concepts that they already know from elsewhere. The aim of this post is to clarify the understanding of these concepts and highlight at least some basic distinguishing features between them.
And I answer the question : Why is the example of the distribution of Fifteen Nette appears in the folder components class called FifteenControl ?;)
Let's start with a nice beginning.
Hierarchy
Inheritance of object-oriented programming enables us to include in the class hierarchy, just like in the real world. We can create a new class derived from others. These derived classes are descended from the original class and inherits the member variables and methods. The derived class may (but need not) add additional functionality (methods and member variables) to have inherited abilities.
For a proper understanding of "how things work" need to know where that class has its roots.
Object
|
+ - Component IComponent ()
|
+ - ComponentContainer IComponentContainer ()
|
+ - (PresenterComponent ISignalReceiver, IStatePersistent)
|
+ - Control IPartiallyRenderable ()
|
+ - Presenter IPresenter () Gradually, we will describe all elements of the hierarchy and in the end it should be clear what are the differences between the concepts mentioned in the introduction.
Nette\Object
At the outset there was a god. So it is (or at least it says) in the real world. In net instead of God we have "basic object, one that does not add any special functionality, but we also appreciate the comfort of work, augmented by PHP things which we would expect from more advanced languages (or rather languages, which have been designed as an object and not become them over time), and also saves you PHP developers zprasili.
Like many of the basic class of objects in net plays an important role, because the hierarchy is always up and used as the basic building block for creating other classes.
See also:
Nette\Component
Component can be understood in several ways.
- First, it is a component, or part, part, building a dynamic website that is not dependent on the surrounding content / objects and easy to make and use. Various examples are JS or Flash viewer of a particular component, manipulators with pictures, search bar, menus, banners, etc. In one site there may be any number. So are most commonly understood components of the people working with Web pages. However, there is a hitch. Nette distinguishes vykreslitelné nevykreslitelné and components.
- The second way can be understood as net "component" is just a basic class - Component . It is precisely the type nevykreslitelné components.
When you think about it, you'll find that the outcome of both views believe the same thing. But we must distinguish ONU vykreslitelnost and clarify it.
- Vykreslitelná component is any object that is a descendant of Control .
- Nevykreslitelná component is just a class that inherits from the Component class, but no longer from the Control class.
Our nevykreslitelná Component base class implements an interface IComponent and it is common for all descendant components, based on her example, all elements of the form. It contains basic methods for serializing and unserializaci, reflecting several methods to detect mainly kinship structures and especially networking (linking) with parents.
In conjunction with ComponentContainer has capabilities to monitor changes to other objects and be aware of them (similar events in other languages).
See also:
- Component
- Component API Reference
- IComponent API reference
Nette\ComponentContainer
ComponentContainer is the basis for storing multiple objects "in one place and serve as a repository for objects and their hierarchy in which objects can thanks to its methods to monitor changes to other objects, or look up the path to them and to their parents and so on. The condition is that these objects will inherit from Component .
Disposal methods for the easy addition, the acquisition and disposal of objects and of course, iteration over its contents.
This class also serves as the parent for the form itself and the class PresenterComponent , Control and Presenter .
See also:
- ComponentContainer
- ComponentContainer API reference
- IComponentContainer API reference
Nette\Application\PresenterComponent
Base class (parent) for all components used in the Presenter . Components are presenter persistent objects, which presenter kept her during your life cycle .
Have the ability to interact poděděné other components to save their positions as persistent (IStatePersistent) and respond to user commands (ISignalReceiver), but not vykreslitelné.
See also:
- PresenterComponent
- PresenterComponent API reference
- ISignalReceiver API reference interface
- IStatePersistent API reference interface
Nette\Application\Control
The term "controller in the other frameworcích, using the MVC design pattern, read the element, which handles the application logic (it C of C MV).
Nette is in control already mentioned vykreslitelná component.
This can have an extra addition that knows how to draw, remember, if at subrequestu changes have occurred which require it to redraw. This is a triptych methods invalidateControl() , validateControl() and isControlInvalid() , which is the basis for the AJAX net.
Nette, however, offers even finer resolution than the level of Control, and the so-called "snippets", or if the counterfoil.
Note: for ease of understanding in the following paragraphs I will take as the Control component. That is vykreslitelná stems from překreslovací features snippets.
It can therefore invalidovat / validation at these snippets (each component can have any number of snippets). If a component is disabled, so every snippet is considered invalid. The component is disabled even if it is disabled some of its subkomponenta. Component that receives the signal is automatically identified as invalid.
Thanks invalidaci snippets we know exactly which parts of which elements would need to repaint.
Component (ie more vykreslitelná Control component) is not a rectangular area within the site, but a logical component that can render into multiple forms. Each component can also be portrayed at times, or conditionally, or each with a different template, etc.
See also:
- Control
- Control API Reference
- IPartiallyRenderable API reference
- Ajax & snippets - snippetům documentation with examples
Nette\Application\Presenter
Presenter represents an instance of a web page. Contains the application logic and the incoming requests trigger corresponding actions.
Using the hierarchy of the PLO takes advantage of all their ancestors and pay for it the same properties, but the advantages and limitations.
Moreover, it is enriched with the possibility of creating links and redirect, redirect to the canonical URL (defined Routama ). Gradually, both through its life cycle is possible to impose the values of its internal state (persistent parameters and components), processes the signals sent components and appropriately respond to them.
See also:
- Presenter
- Presenter API reference
- IPresenter API reference
Model and Module
The model is data and in particular the functional basis for the entire application. The model is a hidden application business logic. Is it the M of M VP (and MVC). The model can be thought of as a state space, a set of conditions to which the application can get. Any event, any action by the user (login, logout, inserting products into your cart, change the values in the database) presents a model of transition from one state to another. It's a black box, which keeps you inside and out of the current state offers fixed interface. Calling features of this interface can detect or modify the internal state model. However, the interface can be accessed by anyone at anytime. [1]
In contrast, the term module is understood as net presenter package, components and templates, but also models, which deliver data presenter. It is therefore a logical part of the application. For example, e-commerce can have three modules:
- Products in cart
- Customer Administration
- administration of service
All three modules of the course could use the same components and models. Then he has yet to understand e-commerce as a module and the above three modules as its submodules. And it allows us to Nette.
Used references and resources:
I) phpguru.cz - Model is not only a database



