Views: 4297 (Data available since 06.02.2017)
Components are subdivided into simple (single page) and composite (compound, multi-page). A simple component displays on one physical page available under a specific URL. A composite component replaces a set of simple components. For example, a news section can be implemented using several simple components located on a separate physical page each, or using one composite component located on one physical page.
In terms of the structure and means of connection, simple and composite components are very similar. However, in terms of functioning, they are very different.
Simple (single page) components create an area on a page surface. They come at hand when you need to render data from different modules on a single page (for example: blogs and information blocks) or data from different information blocks (news and commercial catalog). Evidently, simple components are not convenient to create a whole news section or a catalog because this requires the creation of a considerable number of pages and controlling their linkage.
Composite (compound, multi-page) components create the site sections. For example, the commercial catalog component creates the whole catalog section including the catalogs page, the groups page and the product pages. Essentially, a composite component is a set of pages from the visitor's point of view, but represented by a single page physically. The foundation of composite components are simple components and the use of the single-page logic.
The advantage of composite components is the automatic preparation of parameters of the underlying simple components: you do not have to care about the interrelationships of internal parameters.
Composite components resolve the following problems:
- Avoid the creation of numerous pages to add all required sub-components to them.
There is no need to configure common parameters of each individual component.
- Avoid the need to establish composite associations between sub-components.
For example, you do not have to configure the link creation rules etc.
- Components (even those driven by custom view templates) can be enriched with new pages.
For example, if you add page (sub-component) showing 10 most rated forum visitors, this page becomes momentarily available in the public section.
- The component view template can be changed at one stroke instead of configuring each of the underlying sub-components.
A typical composite component workflow is as follows:
- the component takes user actions on input and defines the exact page to show to a visitor and attaches an appropriate template to the page;
- the page template attaches simple components and configures their parameters as required;
- the simple components perform the requested operations: request data from the system kernel, format and display data to the visitor; show various controls (links, forms, buttons etc.);
- the visitor sends a new request to the composite component using the controls.
Let us consider the difference between composite and simple components using the creation of a news section as an example.
A news section may be organized, for example, by placing a news list component on the page index.php and a detailed news component on the page news.php. In this case, the news list component must have entry parameters set in such a manner so that it could generate links to the page containing the detailed news (with news code). The detailed news component must have entry parameters set in such a manner so that it could generate a link to the page containing the news list.
ЧTo set a link to the page with detailed news the path to this page must be specified along with the name of the parameter in which a news code will be submitted for display. The same parameter name must also be set in the entry parameters of the detailed news component to indicate where it shall retrieve the code of the news to be displayed. Even in this oversimplified case, the settings are not so simple. What if it is a set of tens of components of a forum?
The use of a composite news component is a better option for website developers. For example, this component can be simply installed on the page index.php. The composite component itself will take care of link and parameter alignment. No further actions are required on the part of the website developer.
Template pages of the composite component will contain a connection of the relevant regular components with the correct setting of their entry parameters. Regular components will perform their regular functions: they do no care who retrieves them or why. For regular components, only the correct setting of their entry paramenters is important.
MVC pattern is implemented as follows:
- News composite component (controller) receives an HTTP query (user’s actions);
- News composite component (controller) checks if a news code is set through the HTTP query and connects from its template the page containing the news list or the page containing the detailed news (view);
- The connected page, in its turn, connects the relevant regular component at the same time installing entry paramenters accordingly;
- Regular component performs its work: requests data from the kernel (model), formats them, and displays to the visitor, and also displays control elements (links, forms, buttons, etc.);
- The user sends a new HTTP query to the news composite component (controller) using control elements;
- The procedure is repeated as necessary.