I have tried to move the stuff I usually do in __constructor to initController() method. It seems to work (and I can avoid initializing the things again that have been initialized in the BaseController's initController() function. However, the vscode shows a nasty warning:
Quote:Method 'App\Controllers\Booking::initController()' is not compatible with method 'App\Controllers\BaseController::initController()'.intelephense(1038)
What should I make of that? Is intelephense wrong, or am I not seeing something?
Hard to ignore it psychologically, it triggers me
here is my modified controller (with the previous code commented out:
PHP Code:
class Booking extends BaseController
{
protected $bookingModel;
protected $usersModel;
protected $pagesModel;
protected $roomsModel;
protected $eventTypesModel;
protected $hours;
protected $rooms;
protected $validation;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
$this->bookingModel = model('BookingModel');
$this->usersModel = model('UsersModel');
$this->pagesModel = model('PagesModel');
$this->roomsModel = model('RoomsModel');
$this->eventTypesModel = model('EventTypesModel');
//these lines are in the baseController initController, so I could finally comment them out:
//$this->settingsModel = model('SettingsModel');
//$this->settings = $this->settingsModel->keyValue();
$hl = explode('-', $this->settings['booking_hours']);
$this->hours = range($hl[0], $hl[1]);
$this->rooms = $this->roomsModel->keyValue();
$this->validation = \Config\Services::validation();
}
// public function __construct()
// {
// $this->bookingModel = model('BookingModel');
// $this->usersModel = model('UsersModel');
// $this->pagesModel = model('PagesModel');
// $this->roomsModel = model('RoomsModel');
// $this->eventTypesModel = model('EventTypesModel');
// //dublicates baseConstructor initConstructor()
// $this->settingsModel = model('SettingsModel');
// $this->settings = $this->settingsModel->keyValue();
// $hl = explode('-', $this->settings['booking_hours']);
// $this->hours = range($hl[0], $hl[1]);
// $this->rooms = $this->roomsModel->keyValue();
// $this->validation = \Config\Services::validation();
// }
// the other methods go here
}
==
Donatas G.