本文整理汇总了PHP中Errors::addFieldError方法的典型用法代码示例。如果您正苦于以下问题:PHP Errors::addFieldError方法的具体用法?PHP Errors::addFieldError怎么用?PHP Errors::addFieldError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Errors
的用法示例。
在下文中一共展示了Errors::addFieldError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertMeta
protected function convertMeta(Node $node, NodeSchema &$schema, Errors &$errors, $name, $value, $rawValue)
{
$meta_def = $schema->getMetaDef($name);
$validation = $meta_def->Validation->getValidationArray();
$key = $meta_def->Id;
$fieldTitle = $meta_def->Title;
try {
$value = $this->TypeConverter->convertFromString($meta_def->Validation, $value, $rawValue);
} catch (TypeConversionException $tce) {
$errors->addFieldError('invalid', $this->NodeValidator->resolveField($node->getNodeRef(), $key), 'field', $fieldTitle, $value, $tce->getMessage());
}
return $value;
}
示例2: inputArrayToModel
/**
* Fills the {@link &$model} with values from the {@link $fields}
*
* @param array $fields An array with field names as keys and the values to store.
* @param array $rawFields An array with field names as keys and the raw value as the value.
* Used for 'html' typed fields, for raw access to the field value.
* @param ModelObject &$model The ModelObject we're filling
* @param Errors $errors The Errors object to update if there are any field errors
*
* @return ModelObject Returns &$model after modifications
*/
public function inputArrayToModel(array $fields, array $rawFields, ModelObject &$model, Errors $errors)
{
$fields = array_intersect_key($fields, array_flip($model->getPersistentFields()));
foreach ($fields as $key => $value) {
$datatype = $model->getDatatype($key);
// Clean HTML
if ($datatype === 'html') {
$validation = $model->getValidation($key);
$fields[$key] = $this->InputClean->clean($rawFields[$key], array_key_exists('allowedtags', $validation) ? $validation['allowedtags'] : null);
}
// Convert INT
if ($datatype === 'int' && !empty($value)) {
if (is_numeric($value) === false) {
$errors->addFieldError('invalid', get_class($model) . '.' . $key, 'field', $model->getFieldTitle($key), $value, "Cannot convert string [{$value}] to integer.");
} else {
$fields[$key] = intval($value);
}
}
// Convert FLOAT
if ($datatype === 'float' && !empty($value)) {
if (is_numeric($value) === false) {
$errors->addFieldError('invalid', get_class($model) . '.' . $key, 'field', $model->getFieldTitle($key), $value, "Cannot convert string [{$value}] to float.");
} else {
$fields[$key] = floatval($value);
}
}
// Convert BOOLEAN
if ($datatype === 'boolean') {
$fields[$key] = StringUtils::strToBool($value);
}
// Convert DATE
if ($datatype === 'date' && strlen(trim($value)) > 0) {
try {
$fields[$key] = $this->DateFactory->newLocalDate(trim($value));
} catch (DateException $e) {
$errors->addFieldError('invalid', get_class($model) . '.' . $key, 'field', $model->getFieldTitle($key), $value, "Cannot convert string [{$value}] to date.");
}
}
}
$model->setFromArray($fields);
return $model;
}