本文整理汇总了PHP中Nette\Forms\Controls\BaseControl::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP BaseControl::setValue方法的具体用法?PHP BaseControl::setValue怎么用?PHP BaseControl::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Controls\BaseControl
的用法示例。
在下文中一共展示了BaseControl::setValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* @param object $object
* @param string $fieldName
* @param BaseControl $control
* @param IClassMetadata $classMetadata
* @throws \NForms\Exceptions\UnexpectedTypeException
* @return bool
*/
public function load($object, $fieldName, BaseControl $control, IClassMetadata $classMetadata)
{
if ($classMetadata->hasAssociation($fieldName)) {
if (($value = $classMetadata->getAssociationValue($object, $fieldName)) !== NULL) {
if ($classMetadata->isSingleValuedAssociation($fieldName)) {
if (!is_object($value)) {
throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected object, given " . gettype($value) . ".");
}
$relatedMetadata = $classMetadata->getRelatedMetadata($fieldName);
if (!is_a($value, $relatedMetadata->getClass())) {
throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected NULL or '{$relatedMetadata->getClass()}' instance, given " . get_class($value) . ".");
}
$value = $relatedMetadata->getId($value);
} else {
if (!is_array($value) && (!$value instanceof \ArrayAccess || !$value instanceof \Iterator)) {
throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected array or ArrayAccess and Iterator instance, given " . get_class($value) . ".");
}
$relatedMetadata = $classMetadata->getRelatedMetadata($fieldName);
$value = array_map(function ($object) use($classMetadata, $fieldName, $relatedMetadata) {
if (!is_a($object, $relatedMetadata->getClass())) {
throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected '{$relatedMetadata->getClass()}' instance in collection, given " . get_class($object) . ".");
}
return $relatedMetadata->getId($object);
}, $value);
}
}
} else {
$value = $classMetadata->getFieldValue($object, $fieldName);
}
$control->setValue($value);
return TRUE;
}
示例2: setValue
/**
* @param $value
* @return $this|bool|BaseControl
*/
public function setValue($value)
{
parent::setValue($value);
$this->item = NULL;
if ($value instanceof IdentifiedEntity) {
if (isset($this->items[$value->id])) {
$this->item = $this->items[$value->id];
}
} else {
if (isset($this->items[$this->value])) {
$this->item = $this->items[$this->value];
}
}
return $this;
}
示例3: setValue
public function setValue($value)
{
if ($value instanceof \DoctrineModule\Entities\IEntity) {
return parent::setValue($value->id);
}
}
示例4: loadHttpData
public function loadHttpData()
{
$input = $this->getHttpData(\Nette\Forms\Form::DATA_TEXT);
if (empty($input)) {
parent::setValue(NULL);
return;
}
$datetime = \DateTimeImmutable::createFromFormat($this->normalizeFormat($this->format), $this->normalizeFormat($input));
if ($datetime !== FALSE && $datetime->format($this->normalizeFormat($this->format)) === $this->normalizeFormat($input)) {
parent::setValue($datetime->format($this->format));
return;
}
parent::setValue('');
}
示例5: setValue
/**
* Sets control's value.
*
* @return self
*/
public function setValue($value)
{
if (!$value instanceof \DateTime) {
$value = Nette\Utils\DateTime::from($value);
}
return parent::setValue($value);
}