A
A
Alexander2020-09-24 14:37:31
1C-Bitrix
Alexander, 2020-09-24 14:37:31

How to correctly connect your class through the use construct?

Created two classes in /local/php_interface/lib/
directory DayorderTable - ORM table wrapper DayorderHelper - ORM
helper class

included classes in init.php

Bitrix\Main\Loader::registerAutoLoadClasses(null, [
'DayorderTable' => '/local /php_interface/lib/DayorderTable.php',
'DayorderHelper' => '/local/php_interface/lib/DayorderHelper.php',
]);
Now both classes are visible from anywhere in the project, I can simply access the DayorderTable ORM class on the site page and call the getList method, everything works as it should.

But there is a problem, when in the DayorderHelper.php file I want to make the DayorderTable class visible so that I can access the ORM inside the helper methods, then Bitrix swears, writesClass 'DayordersTable' not

found

use Bitrix\Main;
use Bitrix\Main\Entity;
use Bitrix\Main\Type;
use DayordersTable; // здесь я думаю не правильно указано имя класса ORM с которым работает DayorderHelper в методе GetElement

// Содержит вспомогательные методы для работы с HlbookTable
class DayorderHelper {

    // получаем запись из ORM
    public static function GetElement($deliveryAddress) {
        return $element  = DayordersTable::getList(array(
            'select'  => array('*'), // имена полей, которые необходимо получить в результате
            'filter'  => array('DELIVERY_ADDRESS' => $deliveryAddress), // описание фильтра для WHERE и HAVING
            'limit'   => 1, // количество записей
        ))->fetch();
    }
}


How to correctly connect your class through the use construct so that it becomes visible in the code of another custom class?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PetrPo, 2020-09-24
@inviziblll

// here I think the name of the ORM class with which DayorderHelper works in the GetElement method is not correctly indicated

You think right))
5f6c89996a4d8519558914.jpeg

I
Ilya, 2020-09-24
@rpsv

So-so decision to place classes in php_interface. Create a separate module, include it in init.php (if you always need a module) and that's it. All classes will be loaded automatically according to the class name.
Well, about the wrong name, they already wrote to you in the comments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question