Components are the main tool for developers when it comes to working with the projects created with Bitrix Framework. Developers’ professionalism largely depends on their ability to use this tool.
Classical workflow diagram of a component:
Carrier Rider Mapper
Components implement the design pattern Carrier Rider Mapper to the full extent.
- Carrier. Carrier of any information that can be accessed by several clients simultaneously.
- Rider (Reader or Writer) - objects through which the Carrier provides acces to the information stored in it. The clients read and write information stored in the Carrier exclusively using only the objects of the Reader and Writer type. Thus, Reader and Writer are information access interfaces.
- Mapper (Scanneror Formatter) – objects that cover Reader or Writer, accordingly. Mappers are responsible for the conversion of data formats to the formats convenient for the clients.
Information flow from carrier to client (read): Carrier -> Reader -> Scanner -> Client.
Information flow from client to carrier (write): Carrier <- Writer <- Formatter <- Client.
Introducing mappers between Carrier-Rider and clients permits connecting one and the same Carrier-Rider with different types of clients by using appropriate (different) mappers.
The Use of Components
Components are used for the following purposes:
- Creating fully functionining sections on a website, e.g. news section, photo gallery, goods catalog, etc. These sections are created using composite components;
- Creating frequently used areas in the template or on website pages (e.g., authorization forms and subscription forms);
- Representing dynamically updated information (e.g., news feed and an occasional photo);
- Performing any other operations with data.
When placing a component on a page the user sets parameters that are used to retrieve the page program module on this particular page. The set of parameters (including their types) is to be established in the component parameter file as a special hash array.
Several components may be placed on a website page. One component may be in charge of displaying the text of the article, the second may display banners, the third may display news related to the subject of this article, etc. One and the same component may be used on different pages of the website and on any website within the same product installation.
Components may be simple and composite.
Main Specifics of Component Technique
- Logic and visual form are separated in components. Logic is the component itself, and form is the component display template. Several forms may be created for the same logic, including forms which depend on the template of the current website. Visual form (display template) may be written using any template language that can be connected from PHP. For example, templates may be written using PHP, Smarty, XSL etc.
- There is no need to change the component logic in order to change the specifics of its display. That is why it is quite easy to manage the external appearance of the information displayed by the component. Display template is by far simpler than the component as a whole.
- Components are stored together in one folder. It ensures the integrity and transparency of a website structure. The folder is available for queries. This means the component and its templates can easily connect their additional resources.
In this chapter:
- Simple and composite components
- Location of a Component in the System and Its Connection
- Component Structure
- Composite Component Structure
- Component Description
- Component Parameters
- Component Templates
- Support of Component Classes
- Operation of a Composite Component in a SEF Mode
- Frequent Errors
- Component Caching
- Autocache mode
- Cache Dependencies (Tagged Cache)
- Adding an Own Tag to Component Caches
- Working with Components
- Template Customization
- Modification of a Simple Component Template within a Composite Component
- Template Modification or Creation of result_modifier?
- Component Customization
- Simple Example of a Component Customization
- Modifying a Simple Component as a Part of a Composite One
- Creating Components
- Additional Methods
- Redefinition of Incoming Variables
- User-Defined Templating Engines
- Operation of a Composite Component in SEF Mode
- Ways of Data Transmission among Components
- A Simple Example of a Component Creation
- Component Creation Example
- TinyMCE Visual Editor Integration Component
- Caching in own components
- CUSTOM Parameter Type
- More examples
- Errors When Working with Components