Views: 10701
Last Modified: 10.10.2024

As a matter of fact, today own component may have to be written only when an absolutely new functionality for the website is needed. Since the set of standard components is quite extensive, in most cases just expanding the functionality of the already available components will suffice and there is no need to write new components.

However, sooner or later a developer must learn to create their own components.

Standard Sequence of Operations

  • In a web project, the possible types of own components are identified and described during the drawing up of the terms of reference and design.
  • The namespace of own components is determined, for example, by using the project name. The system components of Bitrix Framework are located in the namespace bitrix, which is where the project components can be located, for example in the namespace citybank.

    Attention! The names of the components to be created must not be the same as the names of standard components.

  • It is determined that a standard component may serve as a basis for creating an own component. The code of standard components contains lots of examples of typical and correct use of API and programming techniques, which is why they are considered a good starting point.
  • An interface is designed for each component 2.0. It should be decided as to which component parameters must be available to the website administrator for editing. For example, for the component displaying a weather forecast, the property Web Service Address and Web Service Connection Timeout may be put in the administrator’s settings, etc.
  • It is decided as to which section of the component tree in the visual editor this component should be located.
  • Component programming. Special attention shall be paid to set up the autocache of the component and its operating profile properly. It must not execute database queries in caching mode, must execute a minimum amount of database queries in case of cache aging, store only necessary data in cache, use a minimum possible volume of RAM (it must not sort arrays of tens or hundreds of megabytes, etc.).

Component Creation Procedure

Make the required php code into a separate file in order to use it later as an invoked file. However, the component must also be connected to the system using a description file identifiable by the core of Bitrix Framework. As a result, a user can see the icon with the component name in the visual editor and can set up the component properties.

Remember that a component consists of a php code with terminated functionality made into a separate file, a file of component registration in the system and its parameter descriptions, and also localization files.

  • Component registration
    • Detachment of a required php code into a separate file.
    • Create the description file .description.php
    • Locate files in a folder in the own namespace.
  • Setting up parameters in the component code
  • Localization
    • Prepare files with text constants for the component and registration file: /lang/en/<component_name>/<component_name>.php and /lang/en/<component_name>/.description.php
    • make changes in the code of both files of the component in order to use these constants (the localization file is connected using the function IncludeTemplateLangFile).

Attention! All keys in $MESS containing the name, description, and parameters of the component and also the identifiers of component branches in the component tree of the visual editor must be unique for the entire product.




Courses developed by Bitrix24