MVC
Model View Controller - simplify client and server communication and presentation
Communication
All code is included in HTML data attributes. Request are generated for button[value] and a[href] tags. Request type is defined by prefix name and it must exists as public method in PHP class. When request is executed, union of all data-* variables from calling tag, form inputs and data-* variables on main div are send as $_POST variables to server. Multiple forms can be linked with data-form="formId" attribute on form tag, so input data can be send with same request. PHP class must process received request and return new content if needed. Multiple contents can be returned to client, each identified by id. Framework replaces HTML content, executes JavaScript code or shows errors on client side. On server side only public methods are executed by client and only defined public class variables are assigned from $_POST array.
<div id="mvcClassName" data-sort="ID" data-offset="10" data-limit="30">
<form id="editForm" data-form="subForm">
<input data-widget="num" data-int="1" type="text" name="numInput"/>
<input type="text" name="txtInput"/>
<button value="#reqSave" data-offset="0" name="saveButton" type="button">
</form>
<form id="subForm">
<input type="text" name="subTxtInput"/>
</form>
</div>
Sends $_POST data to public method reqSave in PHP class:
offset=0
txtInput=<value>
numInput=<value>
subTxtInput=<value>
sort="ID"
limit=30
Requests:
- #req<name> - simple request; defined by button[value^='#req'],a[href^='#req']
- #dialog<name> - request for showing received content in dialog; defined by button[value^='#dialog'],a[href^='#dialog']; first tag attributes in content defines dialog properties
- #download<name> - request for downloading data as file; defined by button[value^='#download'],a[href^='#download']
mvc class
Base mvc class with base properties and methods. All other classes should be extended from this class. All protected methods can be overridden, use inheritance.
Vars
(protected) errors - msgContainer class for sending warnings and errors to client
(protected) response - class for sending response data to client
(public statuc) debug - when enabled, server sends backtrace on exception to client and on client additional debug messages are shown in console
(public statuc) logException - when enabled exceptions are saved in database
Methods
(protected) requires() - override to include additional scripts
(protected) validateAuth() - override to handle special authentification; basic authentification is enabled by default
(protected) jsAdd ($code, $name = null) - add JavaScript code to response stack; executed on client when received request from server
(protected) model() - data module definition (metadata)
(protected) data() - override to get data from datasource in array
(protected) top() - header of HTML page; by default we include system top.inc
(protected) content ($ajaxCall = false) - content to be send to client; if in array multiple content can be send, if returns string all mvc content is replaced
(protected) bottom() - footer of HTML page; by default we include system bottom.inc
(protected) ob ($methodName, $params) - call class method and return output as string
(public) handle() - main calling function; defines data flow of document creation and process requests