Defining controls for CRUD pages

While custom controls for CRUD pages are completely optional, you will need them to handle custom functionality.

To add a view, create a file inside your apps/(projectname)/mvc/controls with the name (modelname)Control.inc.php that extends DefaultControl.

Add a class inside with the name of the file.
So you will have app/test/mvc/views/examplecomplexView.inc.php with the content:

class ExamplecomplexControl extends DefaultControl
{
}

From there you can

Add or override Ajax commands from JavaScript

If you write custom buttons that trigger ajax commands or want to manipulate the default ajax commands, you can handle them here:

class ExamplecomplexControl extends DefaultControl
{

    function handleAjaxCommand(string $command): void
    {

        $model = $this->model;

        if ($command == "exampleAjaxCommand") {

            echo "Ajax test response";
            die();

        }
        else {
            parent::handleAjaxCommand($command);
        }

    }

}

The JQuery call inside your javascript could be like that:

jQuery("#dialogWrapper").on("click", "#button-addedit-test_button", function(e){

    console.log("ajax test call");

    var currentPage = getQueryVariable('p');

    if (currentPage === false){
        currentPage = "";
    }

    var url = "?p=" + currentPage + "&ajaxCall=true&command=exampleAjaxCommand";

    jQuery.ajax({
        type: 'POST',
        url: url,
        data: null,
        processData: false,
        contentType: false,
        cache: false,
        success: function (data) {
            console.log("called exampleAjaxCommand");
            alert("Example Ajax call with result: " + data);
        }
    });

});
WordPress Cookie Plugin by Real Cookie Banner