本文整理汇总了PHP中D::validator方法的典型用法代码示例。如果您正苦于以下问题:PHP D::validator方法的具体用法?PHP D::validator怎么用?PHP D::validator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类D
的用法示例。
在下文中一共展示了D::validator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($metadata, $model, $prefix = '', $prepopulate = array(), $exclude = array(), $disable_groups = false, $disable_widgets = false, $extra_settings = null)
{
$class_name = $metadata->name;
$model_id = $model->id;
$this->table_name = $metadata->table['name'];
$this->prepopulate = \Arr::merge(\Input::get(), $prepopulate);
$this->exclude = $exclude;
$this->disable_groups = $disable_groups;
$this->disable_widgets = $disable_widgets;
$this->title = $model_id && method_exists($model, 'getFormTitle') ? $model->getFormTitle() : $class_name::singular();
if (\Input::param('alias', false) !== false) {
$this->icon = 'link';
$this->plural = 'Links';
$this->singular = 'Link';
} else {
$this->icon = $class_name::icon();
$this->plural = $class_name::plural();
$this->singular = $class_name::singular();
}
// Tabs, Groups, Fields
$this->tabs = $class_name::tabs();
$this->groups = $class_name::groups();
$this->default_tab = $class_name::defaultTab();
$this->default_group = $class_name::defaultGroup();
// Merge in extra field settings
$this->fields = \Admin::getFieldSettings($class_name);
if ($extra_settings !== null && is_array($extra_settings)) {
$this->fields = \Arr::merge($this->fields, $extra_settings);
}
$this->validator_meta = \D::validator()->getMetadataFactory()->getMetadataFor($class_name);
// Merge any DB settings into the mix...
$model_settings = $model->settings;
if (is_array($model_settings)) {
$_model_settings = array();
foreach ($model_settings as $key => $value) {
if (is_array($value) && ($metadata->hasField($key) || $metadata->hasAssociation($key))) {
$_model_settings[$key] = $value;
}
}
$this->fields = \Arr::merge($this->fields, $_model_settings);
}
// The field data
$this->processFieldSettings($metadata, $model, $prefix);
// The group data
$this->processGroups();
// The form structure
$this->processFormStructure();
$this->assets['js'] = array_unique($this->assets['js']);
$this->assets['css'] = array_unique($this->assets['css']);
}
示例2: validate
/**
* Validates the model's properties and association with the Symfony Validator.
* Stores any errors in the model's $errors property.
*
* @param array|null $groups The validator groups to use for validating
* @param array|null $fields Field names to validate. All fields will be validated if omitted.
* @param array|null $fields Field names to exclude from validation
*
* @return bool Whether the model has passed validation
*/
public function validate($groups = null, $fields = null, $exclude_fields = null, $exclude_types = null)
{
$metadata = $this->_metadata();
$result = \D::validator()->validate($this, $groups);
$this->errors = array();
foreach ($result->getIterator() as $violation) {
$prop = $violation->getPropertyPath();
if ($prop == 'id' || $fields !== null && !in_array($prop, $fields) || $exclude_fields !== null && in_array($prop, $exclude_fields)) {
continue;
}
$msg = $violation->getMessage();
$this->addErrorForField($prop, $msg);
}
return count($this->errors) === 0;
}