mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 12:19:28 +00:00
add validation "is_in_db"
This commit is contained in:
@@ -515,3 +515,31 @@ function has_permissions_for_stg($studiengang_kz, $permissions = '')
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if an entry exists in the database
|
||||
*/
|
||||
function is_in_db($key, $model = '')
|
||||
{
|
||||
if (!$model)
|
||||
return false;
|
||||
|
||||
$field = strstr($model, ":");
|
||||
if ($field) {
|
||||
$model = strstr($model, ":", true);
|
||||
$field = substr($field, 1);
|
||||
}
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->model($model, $model);
|
||||
|
||||
if ($field) {
|
||||
$result = $CI->$model->loadWhere([
|
||||
$field => $key
|
||||
]);
|
||||
} else {
|
||||
$result = $CI->$model->load($key);
|
||||
}
|
||||
|
||||
return (isSuccess($result) && hasData($result));
|
||||
}
|
||||
|
||||
@@ -41,3 +41,4 @@ if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
$lang['form_validation_has_write_permissions'] = 'You have no rights to edit {field} field.';
|
||||
$lang['form_validation_is_valid_date'] = 'The date format is invalid or out of range.';
|
||||
$lang['form_validation_has_permissions_for_stg'] = 'You have no rights for stg {field}.';
|
||||
$lang['form_validation_is_in_db'] = '{field} does not exist.';
|
||||
|
||||
Reference in New Issue
Block a user