Bitrix component as a class

13.10.2021 | 1343 | SQL

Using object class.php instead of the traditional component.php at the root of your component.

The class is connected automatically, you do not need to write anything for this.

Create a CBitrixComponent extensible class with an arbitrary name, for example CDevelopernameComponentnameComponent, where you can specify the developer code and the component code / name.
... class CDevelopernameComponentnameComponent extends CBitrixComponent { ...
Two familiar properties are available in this class:
$this->arParams $this->arResult
We create methods that will be called automatically:
onPrepareComponentParams() executeComponent()
In the onPrepareComponentParams () method, it is customary to describe the logic associated with parameters in $ arParams, and in the executeComponent () method, execute the main component logic, the results of which are placed in the $ this-> arResult property.

As a result, my empty component looks like this:
class CDevelopernameComponentnameComponent extends CBitrixComponent {   public function onPrepareComponentParams()   {     // логика связанная с параметрами   }   public function executeComponent()   {     // логика связанная с результатом      $this->includeComponentTemplate(); // call the shiblon component   } }
Of course, it makes sense in a component to describe caching, rights checking, returning parameters to a template, and much more, but that's another story.


← Back

Comments (0)