V
V
Vladimir Golub2018-05-31 13:48:11
1C-Bitrix
Vladimir Golub, 2018-05-31 13:48:11

How to get only json from a component without html and js?

I make a request to the component in the file, in the template file I registered the generation of the required json array, but when I output it, I get this:

<div id="bx_incl_area_1"><pre>
    Array
(
    [files] => Array
        (
            [0] => Array
                (
                    [name] => img.jpg
                    [path] => /upload/iblock/bf4/img.jpg
                    [type] => image/jpeg
                )

            [1] => Array
                (
                    [name] => sample.mp3
                    [path] => /upload/iblock/84e/sample.mp3
                    [type] => audio/mp3
                )

            [2] => Array
                (
                    [name] => sample2.mp3
                    [path] => /upload/iblock/c79/sample2.mp3
                    [type] => audio/mp3
                )

            [3] => Array
                (
                    [name] => Untitled Diagram-3.png
                    [path] => /upload/iblock/1df/Untitled Diagram-3.png
                    [type] => image/png
                )

        )

    [daterequest] => 09.05.2018&nbsp;11:36:00
    [objecthomeid] => Крыша
    [reasonrequestid] => Поломка
    [preferreddate] => 23.05.2018&nbsp;11:36:00
    [statusrequestid] => Завершена
    [datestatus] => 16.05.2018&nbsp;11:36:00
    [content] => Текст
    [sourcerequestid] => Интернет портал
    [typerequestid] => Аварийная
)
</pre>


<script type="text/javascript">if(window.BX)BX.ready(function() {(new BX.CMenuOpener({'parent':'bx_incl_area_1','id':'comp_1','component_id':'ba0b5853288507ea22d99983cf220e31','HINT':{'TITLE':'Новость детально','TEXT':'(компонент bitrix:news.detail)<br />Показывает новость подробно'},'menu':[{'ICONCLASS':'bx-context-toolbar-settings-icon','TITLE':'','TEXT':'Редактировать параметры компонента','ONCLICK':'(new BX.CDialog({\'content_url\':\'/bitrix/admin/component_props.php?component_name=bitrix%3Anews.detail&component_template=requestinfoclient&template_id=jkh&lang=ru&src_path=%2F_ajax%2Frequestinfo.php&src_line=151&src_page=%2F_ajax%2Frequestinfo.php&src_site=s1&siteTemplateId=jkh\',\'width\':\'986\',\'height\':\'625\',\'min_width\':\'450\'})).Show()','DEFAULT':true,'TYPE':'components2_props'},{'ICONCLASS':'bx-context-toolbar-edit-icon','TITLE':'','TEXT':'Изменить элемент','ONCLICK':'(new BX.CAdminDialog({\'content_url\':\'/bitrix/admin/iblock_element_edit.php?IBLOCK_ID=4&type=requests&ID=8&lang=ru&force_catalog=&filter_section=0&bxpublic=Y&from_module=iblock&return_url=%2F_ajax%2Frequestinfo.php&siteTemplateId=jkh\',\'width\':\'700\',\'height\':\'400\'})).Show()','IMAGE':'/bitrix/images/iblock/icons/edit_element.gif'},{'ICONCLASS':'bx-context-toolbar-create-icon','TITLE':'','TEXT':'Добавить элемент','ONCLICK':'(new BX.CAdminDialog({\'content_url\':\'/bitrix/admin/iblock_element_edit.php?IBLOCK_ID=4&type=requests&lang=ru&force_catalog=&filter_section=0&IBLOCK_SECTION_ID=0&bxpublic=Y&from_module=iblock&return_url=%23SITE_DIR%23%2Frequests%2Fdetail.php%3FID%3D%23ELEMENT_ID%23&siteTemplateId=jkh\',\'width\':\'700\',\'height\':\'400\'})).Show()','IMAGE':'/bitrix/images/iblock/icons/new_element.gif'},{'ICONCLASS':'bx-context-toolbar-delete-icon','TITLE':'','TEXT':'Удалить элемент','ONCLICK':'if(confirm(\'Будет удалена вся информация, связанная с этой записью. Продолжить?\'))jsUtils.Redirect([], \'/bitrix/admin/iblock_element_admin.php?IBLOCK_ID=4&type=requests&lang=ru&action=delete&sessid=a961070277bb9a73f0f8c2acfc10a9c4&ID=8&return_url=%2Frequests%2Findex.php%3FID%3D4\')'},{'TYPE':'components2_submenu','TEXT':'components2_submenu','ICON':'parameters-2','MENU':[{'ICONCLASS':'bx-context-toolbar-settings-icon','TITLE':'','TEXT':'Редактировать параметры компонента','ONCLICK':'(new BX.CDialog({\'content_url\':\'/bitrix/admin/component_props.php?component_name=bitrix%3Anews.detail&component_template=requestinfoclient&template_id=jkh&lang=ru&src_path=%2F_ajax%2Frequestinfo.php&src_line=151&src_page=%2F_ajax%2Frequestinfo.php&src_site=s1&siteTemplateId=jkh\',\'width\':\'986\',\'height\':\'625\',\'min_width\':\'450\'})).Show()','DEFAULT':true,'TYPE':'components2_props'},{'TEXT':'Новость детально (bitrix:news.detail)','ICON':'parameters-2','MENU':[{'ICONCLASS':'copy-2','TITLE':'','TEXT':'Копировать шаблон компонента','ONCLICK':'(new BX.CDialog({\'content_url\':\'/bitrix/admin/template_copy.php?lang=ru&component_name=bitrix%3Anews.detail&component_template=requestinfoclient&template_id=jkh&template_site_template=jkh&src_path=%2F_ajax%2Frequestinfo.php&src_line=151&src_site=s1&edit_file=template&back_path=%2F_ajax%2Frequestinfo.php&siteTemplateId=jkh\',\'width\':\'\',\'height\':\'\',\'min_width\':\'450\'})).Show()'},{'ICONCLASS':'edit-2','TITLE':'','TEXT':'Редактировать шаблон компонента','ONCLICK':'(new BX.CEditorDialog({\'content_url\':\'/bitrix/admin/public_file_edit_src.php?site=s1&path=%2Fbitrix%2Ftemplates%2Fjkh%2Fcomponents%2Fbitrix%2Fnews.detail%2Frequestinfoclient%2Ftemplate.php&back_url=%2F_ajax%2Frequestinfo.php&lang=ru&siteTemplateId=jkh\',\'width\':\'1299\',\'height\':\'530\',\'min_width\':\'700\',\'min_height\':\'400\'})).Show()'},{'ICONCLASS':'edit-css','TITLE':'','TEXT':'Редактировать CSS-файл шаблона','ONCLICK':'(new BX.CEditorDialog({\'content_url\':\'/bitrix/admin/public_file_edit_src.php?site=s1&path=%2Fbitrix%2Ftemplates%2Fjkh%2Fcomponents%2Fbitrix%2Fnews.detail%2Frequestinfoclient%2Fstyle.css&back_url=%2F_ajax%2Frequestinfo.php&lang=ru&siteTemplateId=jkh\',\'width\':\'1299\',\'height\':\'530\',\'min_width\':\'700\',\'min_height\':\'400\'})).Show()'},{'ICONCLASS':'del-cache','TITLE':'','TEXT':'Обновить кеш компонента','ONCLICK':'jsComponentUtils.ClearCache(\'component_name=bitrix%3Anews.detail&site_id=s1&sessid=a961070277bb9a73f0f8c2acfc10a9c4\');'},{'SEPARATOR':'Y'},{'ICONCLASS':'','TITLE':'Временно отключить компонент с сохранением настроек','TEXT':'Отключить компонент','ONCLICK':'jsComponentUtils.EnableComponent(\'component_name=bitrix%3Anews.detail&lang=ru&src_path=%2F_ajax%2Frequestinfo.php&src_line=151&src_site=s1&active=N&sessid=a961070277bb9a73f0f8c2acfc10a9c4\');'}]}]}]})).Show()});</script></div><script type="text/javascript">if(window.BX&&BX.admin)BX.admin.setComponentBorder('bx_incl_area_1')</script>

Component call code:
$APPLICATION->IncludeComponent(
  "bitrix:news.detail",
  "requestinfoclient",
  array(
    "ACTIVE_DATE_FORMAT" => "d.m.Y",
    "ADD_ELEMENT_CHAIN" => "N",
    "ADD_SECTIONS_CHAIN" => "N",
    "AJAX_MODE" => "N",
    "AJAX_OPTION_ADDITIONAL" => "",
    "AJAX_OPTION_HISTORY" => "N",
    "AJAX_OPTION_JUMP" => "N",
    "AJAX_OPTION_STYLE" => "N",
    "BROWSER_TITLE" => "-",
    "CACHE_GROUPS" => "Y",
    "CACHE_TIME" => "0",
    "CACHE_TYPE" => "N",
    "CHECK_DATES" => "Y",
    "COMPONENT_TEMPLATE" => "requestinfoclient",
    "DETAIL_URL" => "",
    "DISPLAY_BOTTOM_PAGER" => "N",
    "DISPLAY_DATE" => "Y",
    "DISPLAY_NAME" => "Y",
    "DISPLAY_PICTURE" => "Y",
    "DISPLAY_PREVIEW_TEXT" => "Y",
    "DISPLAY_TOP_PAGER" => "N",
    "ELEMENT_CODE" => "",
    "ELEMENT_ID" => $data["id"],
        "HIDE_ICONS"=>"Y",
    "FIELD_CODE" => array(
      0 => "ID",
      1 => "",
    ),
    "IBLOCK_ID" => "4",
    "IBLOCK_TYPE" => "requests",
    "IBLOCK_URL" => "",
    "INCLUDE_IBLOCK_INTO_CHAIN" => "N",
    "MESSAGE_404" => "",
    "META_DESCRIPTION" => "-",
    "META_KEYWORDS" => "-",
    "PAGER_BASE_LINK_ENABLE" => "N",
    "PAGER_SHOW_ALL" => "N",
    "PAGER_TEMPLATE" => ".default",
    "PAGER_TITLE" => "Страница",
    "PROPERTY_CODE" => array(
      0 => "daterequest",
      1 => "objecthomeid",
      2 => "reasonrequestid",
      3 => "preferreddate",
      4 => "statusrequestid",
      5 => "datestatus",
      6 => "content",
      7 => "houseid",
      8 => "idmc",
      9 => "recieverid",
      10 => "sourcerequestid",
      11 => "typerequestid",
      12 => "file",
      13 => "",
    ),
    "SET_BROWSER_TITLE" => "N",
    "SET_CANONICAL_URL" => "N",
    "SET_LAST_MODIFIED" => "N",
    "SET_META_DESCRIPTION" => "N",
    "SET_META_KEYWORDS" => "N",
    "SET_STATUS_404" => "N",
    "SET_TITLE" => "N",
    "SHOW_404" => "N",
    "STRICT_SECTION_CHECK" => "N",
    "USE_PERMISSIONS" => "N",
    "USE_SHARE" => "N"
  ),
  false
)

Component template code
<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
///** @var array $arParams */
/** @var array $arResult */
///** @global CMain $APPLICATION */
///** @global CUser $USER */
///** @global CDatabase $DB */
///** @var CBitrixComponentTemplate $this */
///** @var string $templateName */
///** @var string $templateFile */
///** @var string $templateFolder */
///** @var string $componentPath */
///** @var CBitrixComponent $component */
//$this->setFrameMode(true);
//?>
<?php
$arrayRequestInfo = [];
$arrayRequestInfo["files"] = [];

foreach($arResult["DISPLAY_PROPERTIES"] as $arProperty) {
    if ($arProperty["CODE"] != "file") {
        $arrayRequestInfo[ $arProperty["CODE"] ] = $arProperty["DISPLAY_VALUE"];
    } else {
        foreach($arProperty["FILE_VALUE"] as $itemFile) {
            $arrayFile = [];
            $arrayFile["name"] = $itemFile["ORIGINAL_NAME"];
            $arrayFile["path"] = $itemFile["SRC"];
            $arrayFile["type"] = $itemFile["CONTENT_TYPE"];

            array_push($arrayRequestInfo["files"], $arrayFile);
        }
    }
}
?>
<pre>
    <?php
        print_r($arrayRequestInfo);
    ?>
</pre>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-05-31
@RazerVG

exit edit mode

A
Alexander Kuznetsov, 2018-09-11
@GeFFest

  1. In the template, we collect the necessary data in an array, put it in $arResult
    This is such a difficult path. In fact, the only way I know how to get an array of data from a component is guaranteed.
    Although your task, most likely, will really be solved by turning off the editing mode.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question