I try to make a custom calendar in my custom component in Joomla 4. For that I write a code who connect to a database and retrieve the data. For that I have 3 files : default.php, ReservationController.php and AjaxReservationController.php. When I change the months in my calendar, I get an Internal Server Error and when I go to the url who are in my default.php I get the Invalid Class Controller : ReservationController.
Here is the code in default.php :
let calendarAvailabilities = {};
let days;
let periods = jQuery.get( "index.php?option=com_skydivespa&task=reservationcontroller.getClosingDays", {"month": cal.getMonth(), "year": cal.getYear()},
function( data ) {
days = JSON.parse(data);
console.info(data);
});
Here is the code in ReservationController.php :
namespace Zzam\Component\SkydiveSpa\Site\Controller;
use ...
class ReservationController extends BaseController {
// Other code
public function getClosingDays()
{
try {
$input = Factory::getApplication()->input;
$month = $input->get('month');
$year = $input->get('year');
// Validate and process the month and year values as needed
$ajaxController = new AjaxReservationController();
$ajaxController->getClosingDays($month, $year);
} catch (Exception $e) {
// Handle the exception
echo 'Error occurred: ' . $e->getMessage();
}
}
And here is the code in AjaxReservationController.php :
namespace Zzam\Component\SkydiveSpa\Site\Controller;
use ...
class AjaxReservationController extends BaseController {
// Other code
public static function getClosingDays($month, $year)
{
try
{
//$month = sprintf("%02s", Factory::getApplication()->input->get('month'));
//$year = Factory::getApplication()->input->get('year');
// Get a database object.
$db = Factory::getContainer()->get('DatabaseDriver');
$query = $db->getQuery(true);
$query->select('p.date_start, p.date_end, p.mon, p.tue, p.wed, p.thu, p.fri, p.sat, p.sun');
$query->from($db->quoteName('#__skydive_periods') . ' AS p');
$query->where('p.type = "PERIOD_r"');
$query->where('p.published = 1');
$query->where('( (MONTH(p.date_start) = '. $month .' AND YEAR(p.date_start) = '. $year .') OR (MONTH(p.date_end) = '. $month .' AND YEAR(p.date_end) = '. $year .') )');
$db->setQuery($query);
$periods = $db->loadObjectList();
$document = Factory::getApplication()->getDocument();
$document->setMimeEncoding('application/json');
echo new JsonResponse($periods);
Factory::getApplication()->close();
}
catch(Exception $e)
{
return new JsonResponse($e);
}
}
I don't know what cause this error. Can you help me ?
EDIT : I added the namespace and class definition. I also tried to change the call to call directly AjaxReservationController but I have the same problem