Abstract Class Yiisoft\FormModel\FormModel
| Inheritance | Yiisoft\FormModel\FormModel |
|---|---|
| Implements | Yiisoft\FormModel\FormModelInterface |
A base class for form models that represent HTML forms: their data, validation and presentation.
Public Methods
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| META_HINT | 2 | Yiisoft\FormModel\FormModel | |
| META_LABEL | 1 | Yiisoft\FormModel\FormModel | |
| META_PLACEHOLDER | 3 | Yiisoft\FormModel\FormModel |
Method Details
| public Yiisoft\FormModel\FormModel addError ( string $message, array $valuePath = [] ) | ||
| $message | string | |
| $valuePath | array | |
public function addError(string $message, array $valuePath = []): static
{
$this->getValidationResult()->addErrorWithoutPostProcessing($message, valuePath: $valuePath);
return $this;
}
| public string getFormName ( ) |
public function getFormName(): string
{
if (str_contains(static::class, '@anonymous')) {
return '';
}
$className = strrchr(static::class, '\\');
if ($className === false) {
return static::class;
}
return substr($className, 1);
}
| public string getPropertyHint ( string $property ) | ||
| $property | string | |
public function getPropertyHint(string $property): string
{
return $this->readPropertyMetaValue(self::META_HINT, $property) ?? '';
}
| public string getPropertyLabel ( string $property ) | ||
| $property | string | |
public function getPropertyLabel(string $property): string
{
return $this->readPropertyMetaValue(self::META_LABEL, $property) ?? $this->generatePropertyLabel($property);
}
| public string getPropertyPlaceholder ( string $property ) | ||
| $property | string | |
public function getPropertyPlaceholder(string $property): string
{
return $this->readPropertyMetaValue(self::META_PLACEHOLDER, $property) ?? '';
}
| public array getPropertyPlaceholders ( ) |
public function getPropertyPlaceholders(): array
{
return [];
}
| public mixed getPropertyValue ( string $property ) | ||
| $property | string | |
public function getPropertyValue(string $property): mixed
{
try {
return $this->readPropertyValue($property);
} catch (PropertyNotSupportNestedValuesException $exception) {
return $exception->getValue() === null
? null
: throw $exception;
} catch (UndefinedArrayElementException) {
return null;
}
}
| public \Yiisoft\Validator\Result getValidationResult ( ) |
public function getValidationResult(): Result
{
if (empty($this->validationResult)) {
throw new LogicException('Validation result is not set.');
}
return $this->validationResult;
}
| public boolean hasProperty ( string $property ) | ||
| $property | string | |
public function hasProperty(string $property): bool
{
try {
$this->readPropertyValue($property);
} catch (ValueNotFoundException) {
return false;
}
return true;
}
| public boolean isValid ( ) |
public function isValid(): bool
{
return $this->isValidated() && $this->getValidationResult()->isValid();
}
| public boolean isValidated ( ) |
public function isValidated(): bool
{
return $this->validationResult !== null;
}
| public void processValidationResult ( \Yiisoft\Validator\Result $result ) | ||
| $result | \Yiisoft\Validator\Result | |
public function processValidationResult(Result $result): void
{
$this->validationResult = $result;
}
Signup or Login in order to comment.