-
What is Bitrix Framework?
-
Production Architecture
-
Production Architecture
-
Structure of files
-
Access Rights
-
A Site in Terms of Bitrix Framework
-
-
Processing Techniques
-
Core D7
-
Modules
-
Name Spaces
-
Core Parameter Setup
-
Exceptions
-
Events
-
Code Writing Rules
-
Applications and Context
-
Errors
-
ORM
-
API
-
Highloadblock
-
-
Design Integration
-
Using Access Rights
-
Site Design Template
-
Using message files for localization
-
Editable areas
-
Navigation tools
-
Advertisement
-
Managing Template Service Data
-
Editing Service Areas
-
Managing Page Encoding
-
Managing Document Header
-
Managing Metadata Values
-
CSS management
-
-
Setup of External Appearance of Additional Elements of the Site Design
-
-
Information Blocks
-
Working with Infoblocks Using Standard Means
-
Infoblocks 2.0
-
Action Plan in Case of Problems
-
Sorting
-
Work with Infoblocks through API
-
Examples
-
-
Components
-
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
-
result_modifier.php
-
component_epilog.php
-
Operation of a Composite Component in a SEF Mode
-
Frequent Errors
-
Component Caching
-
Working with Components
-
Template Customization
-
Component Customization
-
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
-
-
-
Modules
-
Programming in Bitrix Framework
-
Golden Rules
-
The file init.php
-
UTF-8 or a National Encoding?
-
Working with Databases
-
Setup of SEF for URLs
-
Language Files
-
JS Library
-
Interface of the Control Panel Toolbar as Seen by a Developer
-
Some Theory
-
Performance
-
Security
-
Examples, tricks, and advice
-
Custom Fields
-
Gadgets
-
Project Testing
-
Project Quality Control
-
Debugging Web Applications
-
-
Push and Pull module
-
Version Control System
-
-
Multiple Sites
-
Introduction
-
Use of Multiple Site Version
-
How many sites can I create?
-
Language versions (mirrors)
-
Sharing visitors between sites
-
Configuring the multisite system
-
Working with the Data in a Multiple Site Configuration
-
Frequent Questions Arising When Working with a Multiple Site Configuration
-
-
Business Processes for Developer
-
Template of a Business Process
-
Business Process
-
Activities
-
Executing a business process activity using API
-
Arbitrary PHP Code in a Business Process
-
-
Additional Information and Examples
Support of Component Classes
Lesson 116 out of 253
From version 12.0.0 and later, component class support is available. It is implemented in the form of a file /component_name/class.php
. Class.php is a reserved file name, and this file is automatically connected upon retrieval:
$APPLICATION->IncludeComponent()
In this case, the final call of the method initComponent is made, where class.php (if any) is connected from which the most recent inheritor from CBitrixComponent is taken.
The actions like:
class CDemoTest extends CBitrixComponent{} class CDemoTestDecorator1 extends CDemoTest {} class CDemoTestDecorator2 extends CDemoTest {}
will not be successful. As a result, CDemoTestDecorator2 will be used.
Please note that when changing the base class of the component, the behavior of all its descendants (other components) will have to be taken into account.
Examples of Use
Let us consider the simplest component taking the square of a parameter.
File /bitrix/components/demo/sqr/component.php:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); $arParams["X"] = intval($arParams["X"]); if($this->startResultCache()) { $arResult["Y"] = $arParams["X"] * $arParams["X"]; } $this->includeComponentTemplate(); ?>
File /bitrix/components/demo/sqr/templates/.default/template.php
:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> <div class="equation"> <?echo $arParams["X"];?> squared is equal to <?echo $arResult["Y"];?> </div>
In the real components, there may be three dozen lines and 5-6 similar operations instead of the multiplication operation. As a result, the file component.php becomes difficult to understand.
Let us separate the component logic into a class.
File /bitrix/components/demo/sqr/class.php
:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); class CDemoSqr extends CBitrixComponent { //Parent method passes along all of the parameters transferred to $APPLICATION->IncludeComponent //and applies the function htmlspecialcharsex to them. In this case, such processing is excessive. //Redefine. public function onPrepareComponentParams($arParams) { $result = array( "CACHE_TYPE" => $arParams["CACHE_TYPE"], "CACHE_TIME" => isset($arParams["CACHE_TIME"]) ?$arParams["CACHE_TIME"]: 36000000, "X" => intval($arParams["X"]), ); return $result; } public function sqr($x) { return $x * $x; } }?>
File /bitrix/components/demo/sqr/component.php
:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); if($this->startResultCache()) { //$this - an instance of CDemoSqr $arResult["Y"] = $this->sqr($arParams["X"]); } $this->includeComponentTemplate(); ?>
Now the code in the fileе component.php has become controllable.
Component Inheritance
For example:
The file /bitrix/components/demo/double_sqr/class.php
:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die(); //Necessary for the correct search of the class CDemoSqr CBitrixComponent::includeComponentClass("demo:sqr"); //Inheritor that expands functionality: class CDemoDoubleSqr extends CDemoSqr { public function sqr($x) { return parent::sqr($x)*2; } }?>
The file /bitrix/components/demo/double_sqr/component.php
is identical to the file /bitrix/components/demo/sqr/component.php
, the contents can be copied.
The file /bitrix/components/demo/double_sqr/templates/.default/template.php
:
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> <div class="equation"> <?echo $arParams["X"];?> squared multiplied by 2 is equal to <?echo $arResult["Y"];?> </div>
A Component without component.php
A component may also be created without the file component.php
To do so, it is sufficient to deactivate the method executeComponent. For example:
class CDemoSqr extends CBitrixComponent { ... public function executeComponent() { if($this->startResultCache()) { $this->arResult["Y"] = $this->sqr($this->arParams["X"]); } $this->includeComponentTemplate(); return $this->arResult["Y"]; } };
Now, the files component.php can be deleted from both components.