Adding pages with custom content

In most applications you need some pages that have custom content inside.
For example a dashboard with statistics or something very specific for your business case.
In BPFW you can easily do that:

Create a model that is derived from BpfwEmptyModel (NOT BpfwModel).
Set a title and allow access to non admins if required

class ExamplecustomcontentModel extends BpfwEmptyModel
{
    function __construct()
    {
        parent::__construct();
        $this->minUserrankForShow = USERTYPE_USER;
    }


    public function GetTitle(): string
    {
        return "An empty content page. Use the view file to edit the content.";
    }

}

Now you need a view. This time use DefaultView (NOT DefaultListmodelView):
create a renderView method inside for your custom code:


class ExamplecustomcontentView extends DefaultView
{
    // custom content here
    function renderView(): void
    {
        // get the model
        $model = $this->model;

        echo "<div id='customcontent'>Output custom content for this page here</div>";

        // you can also do something like echo json_encode(bpfw_createModelByName("user")->getEntries()); etc. to get the data you need

    }

}

Creating a control is completely optional but in most custom content pages you have some custom ajax commands, so create it as well. This time you can use DefaultControl

<?php /** @noinspection PhpUnused */

class ExamplecustomcontentControl extends DefaultControl
{

    function handleAjaxCommand(string $command): void
    {
         if ($command == "exampleAjaxCommand") {
            echo "Ajax test response";
            die();         
         }
        parent::handleAjaxCommand($command);
    }
}

Remember that you can also add a examplecustomcontentModel.css in apps/yourapp/www/css/ and a examplecustomcontentModel.js in in apps/yourapp/www/js/

That’s it, your result should look something like that:

WordPress Cookie Plugin by Real Cookie Banner