Check_Model Class¶
The Check_Model class provides functions to check validated data, set errors or remove some data.
Creating Check_Model¶
Let's say you want to create bulletin board application. You might have check-model class that contains functions to check data. Here is an example of what such check-model class might look like:
$_GET example:
defined('V_IN_FRONTEND') or die('Powered by <a href="http://www.vesthelm.com/">Vesthelm EE</a>');
class Bulletin_Board_Bulletin_Check_GET extends Vesthelm_Check_Model {
public function id($value) {
$f = __FUNCTION__;
if (!is_array($value) && !$this->bulletin_board->Bulletin->get('', $value)) {
$this->setError(array($f => lang('bulletin_not_found', 'bulletins', 'bulletin_board')));
}
return $this->getErrors($f);
}
}
id() function will check validated data and return error if some data was not specified.
$_POST example:
defined('V_IN_FRONTEND') or die('Powered by <a href="http://www.vesthelm.com/">Vesthelm EE</a>');
class Bulletin_Board_Bulletin_Check_POST extends Vesthelm_Check_Model {
public function id($value) {
$f = __FUNCTION__;
if (empty($value)) {
$this->setError(array($f => lang('field_required')));
}
return $this->getErrors($f);
}
}
id() function will check validated value and return an error if empty value was specified.
Anatomy of Check_Model¶
Check_Model classes are stored in folders:
//Core check-models
example.com/frontend/models
example.com/acp/models
//Application check-models
example.com/applications/{application_name}/frontend/models
example.com/applications/{application_name}/acp/models
//Addon check-models
example.com/addons/{addon_name}/frontend/models
example.com/addons/{addon_name}/acp/models
//Sometimes check-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 check-model class is:
class Enhancement_Name_Check_Model_Name_Check_HTTP_METHOD_NAME extends Vesthelm_Check_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 Check_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 Check_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 (Check_Model_Name_Validate_HTTP_METHOD_NAME). For example, if your class is:
class Bulletin_Board_Bulletin_Check_GET extends Vesthelm_Check_Model {
public function column_name() {}
}
Your file will be:
example.com/applications/bulletin-board/acp/models/Bulletin_Check_GET.php
//or
example.com/applications/bulletin-board/acp/models/bulletin/Bulletin_Check_GET.php
Calling Check_Model¶
Calling Bulletin Board application check-model:
$Bulletin_Check_GET = $this->bulletin_board->Bulletin_Check_GET;
//identical
$Bulletin_Check_GET->get('id');
$this->bulletin_board->Bulletin_Check_GET->get('id');
Where bulletin_board is the name of enhancement and Bulletin_Check_GET is the name of the Check_Model.
Getting Check_Model errors and data¶
$validity_check = $Vesthelm->bulletin_board->Bulletin->validityCheck();
$data = $validity_check['data'];
$errors = $validity_check['errors'];