P
P
photosho2017-05-22 10:19:17
1C-Bitrix
photosho, 2017-05-22 10:19:17

Why might the "BeforeIndexHandler" handler not be called?

Why might the "BeforeIndexHandler" handler not be called? I take the handler declaration from the official site, the code (init.php) is as follows:

AddEventHandler("search", "BeforeIndex", "BeforeIndexHandler");
function BeforeIndexHandler($arFields) {
  echo("проверка");
}

Nothing is output. "AddMessage2Log()" also tried. If "echo" is taken out of the function, then the text written inside is output (that is, the "init.php" file is connected normally). I use the "search.title" component.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yaroslav Alexandrov, 2017-05-22
@alexyarik

What should work here? Take the example and check on the news block
<?
// file /bitrix/php_interface/init.php
// register handler
AddEventHandler("search", "BeforeIndex", Array("MyClass", "BeforeIndexHandler"));
class MyClass
{
// create a "BeforeIndex" event handler
function BeforeIndexHandler($arFields)
{
if($arFields["MODULE_ID"] == "iblock" && $arFields["PARAM2"] == 33)
{
if(array_key_exists(" BODY", $arFields))
{
$arFields["BODY"] .= "latest news";
}
}
return $arFields;
}
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question