Answer the question
In order to leave comments, you need to log in
How to make a Callback in the class method of your module for 1C-Bitrix?
Good afternoon,
for the module used by users from the marketplace (1C-Bitrix), it is necessary to add the ability to change, if necessary, the results of the class methods.
To implement the callback, I used the call_user_func function. Perhaps 1C-Bitrix already has its own Events that can be registered and assigned to your module?
At the moment the code has the following structure:
class myClass {
public function import()
{
$arResult = array();
$arData = array(
'result1',
'result2',
'result3',
);
foreach($arData AS $v)
{
$arResult[] = 'Строка: '.$v;
}
if(function_exists('call_import'))
$arResult = call_user_func('call_import', $arResult);
return $arResult;
}
}
function call_import($arData = array())
{
$arResult = array();
foreach($arData AS $v)
{
$arResult[] = $v.' что то изменили';
}
return $arResult;
}
Answer the question
In order to leave comments, you need to log in
class myClass {
public function import($callback = null)
{
$arResult = array();
$arData = array(
'result1',
'result2',
'result3',
);
foreach($arData AS $v)
{
$arResult[] = 'Строка: '.$v;
}
if (is_callable($callback)) {
call_user_func($callback, $arResult);
}
return $arResult;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question