Documentation

AddEventHandler

AddEventHandler(
 string from_module_id,
 string MESSAGE_ID,
 mixed callback,
 int sort = 100,
 mixed full_path = false
);

The function registers an arbitrary event handler for a callback of the MESSAGE_ID event for the from_module_id. If the full path to the file is specified with the full_path event handler, it will be automatically included prior to calling the event handler. The call is executed on each hit and works until the script stops operation.

Function parameters

ParameterDescription
from_module_id The ID of the module that initiates the event.
MESSAGE_ID The event ID.
callback The name of the handler function. If it is the class method, the array is of the Array(class(object), method name) type.
sort Queue (sequence), in which this handler will be executed (more than one event handler can be registered for this event).
Optional parameter, by default equals 100.
full_path Full path to file to include the event prior to calling the callback.

Note

All the registered event handlers are stored in the global $MAIN_MODULE_EVENTS variable.

See Also

  • RegisterModuleDependences

    Examples of use

    <?
    // script in the file /bitrix/php_interface/init.php
    AddEventHandler("main", "OnBeforeUserLogin", Array("MyClass", "BeforeLogin"));
    class MyClass { function BeforeLogin(&$arFields) { if(strtolower($arFields["LOGIN"])=="guest") { global $APPLICATION; $APPLICATION->throwException("User with the name "Guest" cannot be authorized."); return false; } } } ?>


  • © «Bitrix24», 2001-2024
    Up