Обучаю битриксу программистов, интеграторов. Подробнee ⇒

Свой класс Controller на основе CBitrixComponent



Класс Controller расширяет стандартный битриксовский класс CBitrixComponent
удобен для работы
про компоненты Битрикс - подробная статья с примерами
namespace nikaverro\controller;
use Bitrix\Main\Context;

class Controller extends \CBitrixComponent {
    public $page = '';
    public $request;

    public function __construct(\CBitrixComponent $component = null){       
       parent::__construct($component);
       $this->request = Context::getCurrent()->getRequest();       
    }


    public function executeComponent() {
       if(strlen($this->arParams['controller']) <= 0){
          return false;
       }

       $methodName = $this->arParams['controller'].'Controller';

       if(!method_exists($this, $methodName)){
          throw new \Exception('CONTROLLER_NOT_FOUND');
       }
       
       $this->$methodName();
       
    }

    public function rb() {
       global $APPLICATION;
       $APPLICATION->RestartBuffer();

    }
}

class.php
$this->request - здесь $_REQUEST
use nikaverro\controller\Controller;
use \Bitrix\Main\Application;

class MessageSend extends Controller { 

    function MessageSendController(){
        //моя логика ...        

        $this->arResult = []; //тут результат    
        $this->IncludeComponentTemplate(); 

    }
    function OtherController(){ //другой контроллер

    }     
}

Запуск компонента
$APPLICATION->IncludeComponent(
   "nikaverro.message:nikaverro.message.send", //компонент
   '.default', //шаблон
   ["controller"=>"MessageSend"]  //метод в class.php MessageSendController
);
Если блог был полезным, можете угостить меня "чашечкой кофе" :)

Сбер по номеру телефона +7 (953) 585-13-09 Вероника.
Спасибо!