Loading...
Loading...
Covers creation and maintenance of a custom Bitrix module in /local/modules/<vendor>.<module>/ — CModule class, install/index.php, DoInstall and DoUninstall, install/version.php with $arModuleVersion, registration of events and agents during installation, module options (options.php), generation via make:module. Applied when creating a new module, refining installation/uninstallation, registering event handlers and publishing module options in the Admin Panel. Key terms — CModule, DoInstall, DoUninstall, module manifest, install/index.php, make:module, vendor.module.
npx skill4agent add bxmaximum/bitrix-framework-skills bitrix-modules<vendor>.<module>_<vendor>_<module>_\<Vendor>\<Module>\...\mymodulemymodule\Bitrix\MymoduleBitrix\ucfirst($moduleName)\Mymodulephp bitrix/bitrix.php make:module vendor.modulemake:moduleinstall/index.phpinstall/version.phpinstall/mysql/install.sqlinstall/mysql/uninstall.sqldefault_option.phplang/ru/install/index.php.settings.php/lib/make:*dev:module-skeleton/local/modules/vendor.module/
├── install/
│ ├── index.php
│ ├── version.php
│ └── mysql/ # optional SQL stubs from make:module
├── lang/ru/install/index.php
├── default_option.php
├── lib/ # PSR-4, Vendor\Module\... (add manually)
├── views/ # PHP views for renderView() in controllers
├── routes/ # Module route files — require from /local/routes/web.php
├── .settings.php # controllers, services, console (add manually)
└── include.php # optional, for registerNamespace/registerAutoLoadClassesrouting.config/local/routes//bitrix/routes/routing.settings.phprequire/local/routes/web.php// /local/routes/web.php
return function (\Bitrix\Main\Routing\RoutingConfigurator $routes): void {
$moduleRoutes = $_SERVER['DOCUMENT_ROOT'] . '/local/modules/vendor.module/routes/web.php';
if (is_file($moduleRoutes))
{
(require $moduleRoutes)($routes);
}
};install/version.php<?php
$arModuleVersion = [
'VERSION' => '1.0.0',
'VERSION_DATE' => '2026-04-16 12:00:00',
];install/index.phpCModuleDoInstallDoUninstall<?php
use Bitrix\Main\Localization\Loc;
use Bitrix\Main\ModuleManager;
use Bitrix\Main\EventManager;
Loc::loadMessages(__FILE__);
final class vendor_module extends CModule
{
public $MODULE_ID = 'vendor.module';
public $MODULE_VERSION;
public $MODULE_VERSION_DATE;
public $MODULE_NAME;
public $MODULE_DESCRIPTION;
public $PARTNER_NAME = 'Vendor';
public $PARTNER_URI = 'https://vendor.example.com';
public function __construct()
{
$arModuleVersion = [];
include __DIR__ . '/version.php';
$this->MODULE_VERSION = $arModuleVersion['VERSION'] ?? '';
$this->MODULE_VERSION_DATE = $arModuleVersion['VERSION_DATE'] ?? '';
$this->MODULE_NAME = (string)Loc::getMessage('VENDOR_MODULE_NAME');
$this->MODULE_DESCRIPTION = (string)Loc::getMessage('VENDOR_MODULE_DESCRIPTION');
}
public function DoInstall(): void
{
global $USER, $APPLICATION;
if (!$USER->IsAdmin())
{
$APPLICATION->ThrowException('Access denied');
return;
}
ModuleManager::registerModule($this->MODULE_ID);
$this->installDb();
$this->installEvents();
$this->installAgents();
$this->installFiles();
}
public function DoUninstall(): void
{
global $USER;
if (!$USER->IsAdmin()) return;
$this->uninstallAgents();
$this->uninstallEvents();
$this->uninstallDb();
$this->uninstallFiles();
ModuleManager::unRegisterModule($this->MODULE_ID);
}
private function installDb(): void
{
// Table creation via ORM Entity:
// \Vendor\Module\Model\PostTable::getEntity()->createDbTable();
}
private function uninstallDb(): void
{
// Application::getConnection()->dropTable(PostTable::getTableName());
}
private function installEvents(): void
{
EventManager::getInstance()->registerEventHandler(
fromModule: 'main',
eventType: 'OnAfterUserAdd',
toModuleId: $this->MODULE_ID,
toClass: \Vendor\Module\Internals\Integration\Main\EventHandler\OnAfterUserAddHandler::class,
toMethod: 'handle',
);
}
private function uninstallEvents(): void
{
EventManager::getInstance()->unRegisterEventHandler(
fromModule: 'main',
eventType: 'OnAfterUserAdd',
toModuleId: $this->MODULE_ID,
toClass: \Vendor\Module\Internals\Integration\Main\EventHandler\OnAfterUserAddHandler::class,
toMethod: 'handle',
);
}
private function installAgents(): void
{
\CAgent::AddAgent(
\Vendor\Module\Cli\Agent\QueueAgent::class . '::run();',
$this->MODULE_ID,
'N',
300,
'',
'Y',
'',
100,
);
}
private function uninstallAgents(): void
{
\CAgent::RemoveModuleAgents($this->MODULE_ID);
}
private function installFiles(): void
{
CopyDirFiles(
__DIR__ . '/components',
$_SERVER['DOCUMENT_ROOT'] . '/local/components',
true,
true,
);
}
private function uninstallFiles(): void
{
DeleteDirFilesEx('/local/components/vendor');
}
}/local/modules/vendor.module/lang/ru/install/index.phpmake:module<?php
$MESS['VENDOR_MODULE_NAME'] = 'Vendor Module';
$MESS['VENDOR_MODULE_DESCRIPTION'] = 'Module description';lang/en//install/index.php/lang/<code>/install/index.php/admin/my_page.php/lang/<code>/admin/my_page.phpMODULE_NAMEMODULE_DESCRIPTION/lib/Model/PostTable.php\Bitrix\Main\Loader::includeModule('vendor.module');
\Vendor\Module\Model\PostTable::getEntity()->createDbTable();\Bitrix\Main\Application::getConnection()->dropTable(PostTable::getTableName());options.phpOptiondefault_option.phpbitrix-storage<?php
/** @var CMain $APPLICATION */
/** @var string $mid */ // module id
use Bitrix\Main\Config\Option;
use Bitrix\Main\Localization\Loc;
$options = [
['api_key', Loc::getMessage('VENDOR_API_KEY'), '', ['text', 40]],
['debug_mode', Loc::getMessage('VENDOR_DEBUG'), 'N', ['checkbox', 'Y']],
];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && check_bitrix_sessid())
{
foreach ($options as $opt)
{
$val = $_POST[$opt[0]] ?? $opt[2];
Option::set($mid, $opt[0], $val);
}
}
// ... display via CAdminTabControlinclude.php/local/modules/vendor.module//lib/\Vendor\Module\...\Bitrix\Mymodule\...LoaderincludeModulevendor.module\Bitrix\...make:module.settings.phplib/require/local/routes/web.php.settings.phproutingDoInstallDoUninstallSqlHelperlang/ru/lang/en/.settings.phpindex.phpLoc/local//bitrix/