Как получить доступ к классу при работе со свойствами инфоблока в Bitrix?

Рейтинг: 0Ответов: 1Опубликовано: 03.03.2023

Я хотел написать класс для упрощенной работы с свойствами инфоблока...

<?php

namespace Infoblock\Property;


class Property{
    private $arItem;
    function __construct($setArItem) {
        $this->arItem = $setArItem;
    }
    function getImgURL($nameImg){
        $dataImageInProperty = CFile::GetFileArray($this->arItem[$nameImg]['VALUE']);
        return $dataImageInProperty['SRC'];
    }
}

?>

В результате получил данную ошибку:

Undefined type 'Infoblock\Property\CFile'

Подскажите пожалуйста, как получить доступ к классу CFile?

Ответы

▲ 1

Необходимо указать правильный неймспейс для класса CFile.

1 вариант

<?php

namespace Infoblock\Property;
use \CFile;

class Property{
    private $arItem;
    function __construct($setArItem) {
        $this->arItem = $setArItem;
    }
    function getImgURL($nameImg){
        $dataImageInProperty = CFile::GetFileArray($this->arItem[$nameImg]['VALUE']);
        return $dataImageInProperty['SRC'];
    }
}

?>

Второй

<?php

namespace Infoblock\Property;


class Property{
    private $arItem;
    function __construct($setArItem) {
        $this->arItem = $setArItem;
    }
    function getImgURL($nameImg){
        $dataImageInProperty = \CFile::GetFileArray($this->arItem[$nameImg]['VALUE']);
        return $dataImageInProperty['SRC'];
    }
}

?>