myMVC_BaseActionBase class for all actions.
You must derive your action's classes from this class.
In the constructor you must define one or more function to validate the input.
Use the method setCheckFunction() to do that.
Example to validate input:
Every field (with the name of the form!!) must have an associative array with
the check type and his parameters.
$definitions is an associative array with the description of the checks.
$names is an associative array with the name of the fields, used for the error message.
$errorMsgs is an associative array with the possible errors. For every check of the field, it should contain a description of the error. {field} is a placeholder for the name of the field (see $names). {checkValue} is a placeholder for the given value for the check (for example: 'min' => 2).
If $errorMsg does not contain a message for the current error, it will just return '{field} is not valid' (parsed with GetText)
$definition has to be created as follow:
In myMVC_BaseAction there are many $VALIDATE_xxx defines to validate the different input fields.
Every validate-check can have more parameters.
In the following example-code you can find the validate-checks with their parameters explained.
You can give more than one parameter for every check.
Valid parameters for all checks (but $VALIDATE_EXTERN and $VALIDATE_UPLOAD) are:
empty true or false. It decides wheter an empty field should be accepted.
range array of valid values for the checked field.
rangei same as range, but case insensitive (just for $VALIDATE_STRING, $VALIDATE_EMAIL and $VALIDATE_WEB).
rangesql SQL-query to get the valid values for the checked field.
rangesqli same as rangesql, but case insensitive (just for $VALIDATE_STRING, $VALIDATE_EMAIL and $VALIDATE_WEB).
comparedb Execute an SQL-query and compare the result with the given value.
In the query you can use {checkValue} as placeholder for the user's given input value. See example to use it.
WARNING: the query must return just one record with one column, otherwise it throws an exception.
comparefield like comparedb, but it compares two input fields. Useful for action like "password change", when the user has to give the password twice.
$VALIDATE_NUMBER has 'min' and 'max', too, to restrict the valid numbers into a range.
$VALIDATE_DATETIME has 'format' to give the format of the date (see strftime). This parameter is mandatory!
$VALIDATE_STRING has the parameters 'minlen' and 'maxlen' to restrict the length of the input string, and the parameter 'regexp' to check the string against a given regular expression.
$VALIDATE_EXTERN has just the parameter 'checkFunction'. See the example. $VALIDATE_UPLOAD has the parameters 'minlen' (in KB), 'maxlen' (in KB), 'empty' and 'allowed_types'. See the example. PLEASE REMENBER TO SET 'upload_max_filesize' in your php.ini!!
If a required parameter wasn't given, the Framework generates an Exception.
this function must return true if data are valid, and false otherwise. In this case, $errMsg can contain an error message, that will be parsed with $errorMsgs (placeholder: {externError}).
If you want to call the Action as AJAX, you can (but not must) define the methods performAjax() and manageInvalidDataAjax() with same parameters of perform() and manageInvalidData(). To validate the data, you should pass "AJAX" as first parameter to setCheckFunction(). So you can have an Action that supports normal calls (GET and/or POST) and AJAX
Located in /myMVC/BaseAction.php (line 194)
myMVC_BasePage | --myMVC_BaseAction
| Class | Description |
|---|---|
myMVC_BaseLogoutAction
|
Action-class to manage a login system. |
myMVC_BaseLoginAction
|
Action-class to manage a login system. |
static mixed
$ERROR_COMPAREDB
= 'comparedb' (line 289)
Error not matched in compare database
static mixed
$ERROR_COMPAREFIELD
= 'comparefield' (line 293)
Error not matched in compare fields
static mixed
$ERROR_EMPTY
= 'empty' (line 277)
Error empty
static mixed
$ERROR_INVALID
= 'invalid' (line 297)
Error invalid (generic)
static mixed
$ERROR_INVALIDTYPE
= 'invalidtype' (line 301)
Error invalid type for upload
static mixed
$ERROR_MAX
= 'max' (line 261)
Error greater than given maximum
static mixed
$ERROR_MAXLEN
= 'maxlen' (line 269)
Error longer than given maximum
static mixed
$ERROR_MIN
= 'min' (line 265)
Error lesser than given minimum
static mixed
$ERROR_MINLEN
= 'minlen' (line 273)
Error smaller than given minimum
static mixed
$ERROR_NOTBOOL
= 'notbool' (line 237)
Error not boolean
static mixed
$ERROR_NOTDATETIME
= 'notdatetime' (line 241)
Error not date/time
static mixed
$ERROR_NOTEMAIL
= 'notemail' (line 245)
Error not E-Mail
static mixed
$ERROR_NOTNUMBER
= 'notnumber' (line 249)
Error not numeric
static mixed
$ERROR_NOTSTRING
= 'notstring' (line 253)
Error not string
static mixed
$ERROR_NOTWEB
= 'notweb' (line 257)
Error not URL
static mixed
$ERROR_RANGE
= 'range' (line 281)
Error not in given range
static mixed
$ERROR_REGEXP
= 'regexp' (line 285)
Error not matched in regular expression
static mixed
$ERROR_UPLOADERROR
= 'uploaderror' (line 305)
Generic error for upload
static mixed
$VALIDATE_BOOLEAN
= 'bool' (line 204)
Check for a boolean value
static mixed
$VALIDATE_DATETIME
= 'dateTime' (line 212)
Check for a date/time value
static mixed
$VALIDATE_EMAIL
= 'email' (line 216)
Check for an E-Mail
static mixed
$VALIDATE_EXTERN
= 'extern' (line 228)
Check using external function
static mixed
$VALIDATE_NUMBER
= 'number' (line 208)
Check for a numeric value
static mixed
$VALIDATE_STRING
= 'string' (line 224)
Check for a generic string
static mixed
$VALIDATE_UPLOAD
= 'upload' (line 232)
Check for upload file
static mixed
$VALIDATE_WEB
= 'web' (line 220)
Check for an URL
mixed
$renderEngine
(line 196)
mixed
$request
(line 197)
mixed
$session
(line 198)
static getActionMenuName (line 394)
Returns the string to be displayed in the menu to identify the current action.
Only necessary if isMenuAction() returns true
static getActionMenuPosition (line 405)
Returns the position of this action in the menu (created by controller) Only necessary if isMenuAction() returns true
static getActionToken (line 386)
Returns the token used to identify the current Action
static getCSSClass (line 422)
Returns the CSS class of this action
static hasUserRightForAction (line 415)
Returns whether the current user is allowed to call the current Action
static isMenuAction (line 432)
Returns whether this action should appear in the menu (created by controller)
Constructor __construct (line 313)
Constructor
getNumber (line 1114)
Convert a number to the internal PHP-Format, using current user's locale
getRenderEngine (line 337)
Return the current used render engine.
isCalledFromMenu (line 454)
Returns if the current action was called from menu or from a view
isComingFromView (line 443)
Returns whether this action was called from the given view
manageInvalidData (line 521)
Called if user data are not valid (check with validate)
perform (line 510)
Perform the Action
saveRenderEngine (line 327)
Save the current used render engine.
It can be used to instanciate Mailview to be used in MessageManager
setCheckFunction (line 350)
Set the functions to be used to validate the user's input.
validate (line 468)
Validate the data from user.
It call the proper validate function, depending on the request method (GET or POST), to allow different checks. WARNING: this function should not be overrided! Please create proper validatePost() or validateGet() functions!
validateInput (line 765)
Check if the given data (from Request) are valid.
The function save in the session (namespace: validate) an associative array with the invalid fields.
Inherited From myMVC_BasePage
myMVC_BasePage::__construct()
myMVC_BasePage::getFromPreviousSubmit()
myMVC_BasePage::getInvalidFromPreviousSubmit()
myMVC_BasePage::getLoggedUser()
myMVC_BasePage::getParameterErrors()
myMVC_BasePage::getParameterFromPreviousPage()
myMVC_BasePage::isParameterFromPreviousSubmitValid()
myMVC_BasePage::saveParameterForNextPage()
Documentation generated on Mon, 14 Mar 2016 18:20:29 +0100 by phpDocumentor 1.4.4