Задать вопрос
  • Работа с контроллерами в 1с-битрикс?

    @veldeta Автор вопроса
    Спасибо, проблема была выяснена. Оказалось что мне нужно было всего-то установить модуль в систему, чтобы она видела новые модули. Как я её добавил в систему, сразу посыпались другие ошибки, которые были исправлены по мере поступлении. Теперь все работает!
    Спасибо что помогли!
  • Работа с контроллерами в 1с-битрикс?

    @veldeta Автор вопроса
    <?php
    
    namespace Vendor\Example\Controller;
    
    use \Bitrix\Main\Error;
    
    class Item extends \Bitrix\Main\Engine\Controller
    {
    
        private $actionsConfig = [
            'view' => [
                '-prefilters' => [
                    '\Bitrix\Main\Engine\ActionFilter\Authentication'
                ]
            ],
            'add' => [
                '-prefilters' => [
                    '\Bitrix\Main\Engine\ActionFilter\Authentication'
                ]
            ]
        ];
    
        public function init()
        {
            parent::init();
            foreach($this->actionsConfig as $name => $arConfig) $this->setActionConfig($name, $arConfig);
        }
        
        public function addAction(array $fields):? array
        {
            $item = Item::add($fields);
    
            if (!$item)
            {
                $this->addError(new Error('Could not create item.', 500));
    
                return null;
            }
    
            return $item->toArray();
        }
    
        public function viewAction($id):? array
        {
            $item = Item::getById($id);
            if (!$item)
            {
                $this->addError(new Error('Could not find item.',404));
                        
                return null;
            } 
    
            return $item->toArray();
        }
    }

    <?php
    //modules/vendor.example/.settings.php
    return [
        'controllers' => [
            'value' => [
                'defaultNamespace' => '\\Vendor\\Example\\Controller',
            ],
            'readonly' => true,
        ]
    ];

    BX.ajax.runAction('vendor:example.Item.add',{
        data: {
            fields: {
                ID: 1,
                NAME: "test"
            } 
        }
    }).then(function (response) {
        console.log(response);		
    }, function (response) {
        console.log(response);			
    });


    Писал все так как было показано в примере
  • Работа с контроллерами в 1с-битрикс?

    @veldeta Автор вопроса
    Добавил, но проблема не ушла =(