Validate_Model Class¶
The Validate_Model class provides functions to validate $_GET and $_POST data.
Creating Validate_Model¶
Let's say you want to create bulletin board application. You might have validate-model class that contains functions to validate bulletin board application $_POST and $_GET data. Here is an example of what such validate-model class might look like:
$_GET example:
URL:
http://example.com/index.php?id=10
defined('V_IN_FRONTEND') or die('Powered by <a href="http://www.vesthelm.com/">Vesthelm EE</a>');
class Bulletin_Board_Bulletin_Validate_GET extends Vesthelm_Validate_Model {
public function id() {
$f = __FUNCTION__;
$value = $this->Input->get($f);
$value = intval($value);
return $value;
}
}
id() function will validate $_GET['id'] value and returns the integer value: 10.
$_POST example:
defined('V_IN_FRONTEND') or die('Powered by <a href="http://www.vesthelm.com/">Vesthelm EE</a>');
class Bulletin_Board_Bulletin_Validate_POST extends Vesthelm_Validate_Model {
public function id() {
$f = __FUNCTION__;
$value = $this->Input->post($f);
$value = intval($value);
return (int) $value;
}
}
id() function will validate $_POST['id'] value and returns the integer value.
Anatomy of Validate_Model¶
Validate_Model classes are stored in folders:
//Core validate-models
example.com/frontend/models
example.com/acp/models
//Application validate-models
example.com/applications/{application_name}/frontend/models
example.com/applications/{application_name}/acp/models
//Addon validate-models
example.com/addons/{addon_name}/frontend/models
example.com/addons/{addon_name}/acp/models
//Sometimes validate-models can be found here (old way):
example.com/addons/{addon_name}/frontend/classes
example.com/addons/{addon_name}/acp/classes
The basic prototype for validate-model class is:
class Enhancement_Name_Validate_Model_Name_Validate_HTTP_METHOD_NAME extends Vesthelm_Validate_Model {
public function column_name() {}
}
Where Enhancement_Name is the name of your enhancement. Enhancement names must have the first letter capitalized after underscore _ character.
Where Validate_Model_Name is the name of your class. Class names must have the first letter capitalized after underscore _ character. Make sure your class extends the base Validate_Model class.
Where HTTP_METHOD_NAME is one of the HTTP methods (POST or GET).
The file name will be same as your class name (Validate_Model_Name_Validate_HTTP_METHOD_NAME). For example, if your class is:
class Bulletin_Board_Bulletin_Validate_GET extends Vesthelm_Validate_Model {
public function column_name() {}
}
Your file will be:
example.com/applications/bulletin-board/acp/models/Bulletin_Validate_GET.php
//or
example.com/applications/bulletin-board/acp/models/bulletin/Bulletin_Validate_GET.php
Calling Validate_Model¶
Calling Bulletin Board application validate-model:
$Bulletin_Validate_GET = $this->bulletin_board->Bulletin_Validate_GET;
//identical
$Bulletin_Validate_GET->get('id');
$this->bulletin_board->Bulletin_Validate_GET->get('id');
Where bulletin_board is the name of enhancement and Bulletin_Validate_GET is the name of the Validate_Model.