0

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

3
  • The problem is not with the code that you have posted but with the definition of the class ReservationController. The message is suggesting it has a typo or wrong case letter in the class statement or the filename containing the class or if you are using Namespaces then your class may not be installed or loaded correctly. You should paste in your question the Class and Namespace statements that appear towards the beginning of ReservationControlloer.php
    – Irata
    Commented Jun 22, 2023 at 9:58
  • Is it because of the task value in the default.php file? You have "task=reservationcontroller.getClosingDays" but shouldn't it be "task=reservation.getClosingDays"? Commented Jun 30, 2023 at 3:40
  • I tried with task=reservation.getClosingDays but nothing changed.
    – Sephirah
    Commented Jun 30, 2023 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.