E
E
Express7772015-01-06 13:26:47
1C-Bitrix
Express777, 2015-01-06 13:26:47

How to automatically generate a link to an element in 1C Bitrix?

Hello.
This task was the result of another task: to make CNC on the site.
Previously, links on the site were of the form site.ru/section/?ELEMENT_ID=number_id_element
Enabled CNC in the settings of each component. Now links like site.ru/section/character_code of the element
CNC settings in the component: joxi.ru/vAWV9nPf36qq2W or radikal.ru/fp/b95ab9778bc8432a8d12c50b5e295eb2 The
CNC works fine.
BUT there is one but. The main page has a News component that generates a list of portfolios with links. Links are hardcoded in each element. They are set in "Link (logo on the main page)":
joxi.ru/8An3kqRINnj1rO or radikal.ru/fp/efa400d2dc804bdda6e3b2d56d9f8639
It is a property of the infoblock:
joxi.ru/p27gBPNuL5on27 or radikal.ru/fp/84c83ce739634a88bb0b55aa78a0b51d The
HTML code is generated by the code:

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<div id="clicont">
<?foreach($arResult["ITEMS"] as $arItem):?>
    <?
    $this->AddEditAction($arItem['ID'], $arItem['EDIT_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_EDIT"));
    $this->AddDeleteAction($arItem['ID'], $arItem['DELETE_LINK'], CIBlock::GetArrayByID($arItem["IBLOCK_ID"], "ELEMENT_DELETE"), array("CONFIRM" => GetMessage('CT_BNL_ELEMENT_DELETE_CONFIRM')));
    ?>
    <?if($arParams["DISPLAY_PICTURE"]!="N" && !empty($arItem["DISPLAY_PROPERTIES"]["LOGO"]["VALUE"])):?>
        <?$arrImages = !is_array($arItem["DISPLAY_PROPERTIES"]["LOGO"]["VALUE"]) ? array($arItem["DISPLAY_PROPERTIES"]["LOGO"]["VALUE"]) : $arItem["DISPLAY_PROPERTIES"]["LOGO"]["VALUE"];
        foreach($arrImages as $imgID) {?>
      //Вот тут он берет значение свойства LINKS !!!
            <a href="<?=$arItem["PROPERTIES"]["LINKS"]["VALUE"]   ?>" class="client_<?=$arItem['ID']?>">
            <?echo CFile::ShowImage($imgID, 100, 100, 'border="0" style="float:left;height: 56px;" ');?>
            </a>
        <?}
        ?>
    <?endif?>
<?endforeach;?>
</div>

Here's how to get the character code of an element in 1C Bitrix in PHP code?
And replace the ?ELEMENT_ID=XXX part in $arItem["PROPERTIES"]["LINKS"]["VALUE"] with a character code?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MintTea, 2015-01-07
@Express777

1) Set the url settings in the infoblock settings. Something like this: Rmze1GJTvwD8rO.png
2) In php, change all this nonsense with an additional property to display the variable $arItem['DETAIL_PAGE_URL']

F
Fyodor Buzinov, 2015-01-07
@Feduch

In joxi.ru/p27gBPNuL5on27 I would change the type of the property to be bound to the element, then in the result_modifier.php of the template, by ID from this property I would get the DETAIL_PAGE_URL of the bound element, the value will be in the desired form

E
Express777, 2015-01-07
@Express777

While I made such a crutch:

<?//Доделать проверку на соответвие шаблону, только тогда менять
      $string = $arItem["PROPERTIES"]["LINKS"]["VALUE"];
      $pattern = '/\?ELEMENT_ID=[0-9]+/';
      $replacement = $arItem["CODE"]; // символьный код хранится в массиве с ключом "CODE"
      $href_string = preg_replace($pattern, $replacement, $string);
            
      ?>
            <a href="<?=$href_string."/"?>" class="client_<?=$arItem['ID']?>">
            <?echo CFile::ShowImage($imgID, 100, 100, 'border="0" style="float:left;height: 56px;" ');?>
            </a>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question