Active Record Controller

An active record controller encapsulates all of the screens required to manage an active record. The default implementation provided by the framework includes these standard CRUD screens:

• An index screen which shows a display table of all records in the database• A create screen which displays and processes the form for creating a new record• An edit screen which displays and processes the form for editing an existing record• A view screen which shows the currently stored values for an existing record• A delete screen which confirms the deletion of an individual record

@Create A Controller

You can use an active record class to create a controller that manages its associated database records. You can customize many aspects of the active record controller through the config array passed when you create it.

@Use A Custom Controller

If you would like to expand on the existing screens provided by the default implementation by adding new ones, or customize the behavior of existing screens, then you can create your own class which extends the MWP\Framework\Helpers\ActiveRecordController class and assign it as the controller class for your active record before you begin creating.

@How A Controller Works

When a controller is created, the controller object instance is registered as a handler for all requests to the associated admin page defined in the controller configuration.

Any time the controller is going to handle rendering a page, the init() method on the controller is called which allows the controller to perform any pre-processing of the page request (such as internal setup, or authorization checks). When the page is loaded, the do_index() method on the controller instance is called to process the request and render the page.

If a &do=action parameter exists on the page request, then the method which is called to process the page changes to do_action(). The base active record controller handles requests for the following actions:

do_index()Renders an active record display table (no ‘do’ parameter in url, or do=index)do_view()Renders an individual record view (do=view parameter in url)do_edit()Renders a record editing form (do=edit parameter in url)do_new()Renders a record creation form (do=new parameter in url)do_delete()Confirms and deletes a record (do=delete parameter in url)