本文整理汇总了PHP中Zend\Form\Element\Select::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP Select::setValue方法的具体用法?PHP Select::setValue怎么用?PHP Select::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Element\Select
的用法示例。
在下文中一共展示了Select::setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
/**
* @param mixed $value
* @throws \Zend\Form\Exception\InvalidArgumentException
* @return void|\Zend\Form\Element
*/
public function setValue($value)
{
if (is_string($value)) {
try {
$value = new PhpDateTime($value);
} catch (Exception $e) {
throw new InvalidArgumentException('Value should be a parsable string or an instance of \\DateTime');
}
}
if (is_null($value)) {
$value = new PhpDateTime();
}
if ($value instanceof PhpDateTime) {
$value = array('year' => $value->format('Y'), 'month' => $value->format('m'), 'day' => $value->format('d'), 'hour' => $value->format('H'), 'minute' => $value->format('i'), 'second' => $value->format('s'));
}
if (!isset($value['second'])) {
$value['second'] = '00';
}
$this->yearElement->setValue($value['year']);
$this->monthElement->setValue($value['month']);
$this->dayElement->setValue($value['day']);
$this->hourElement->setValue($value['hour']);
$this->minuteElement->setValue($value['minute']);
$this->secondElement->setValue($value['second']);
}
示例2: setValue
/**
* @param mixed $value
* @return void|\Zend\Form\Element
*/
public function setValue($value)
{
if ($value instanceof PhpDateTime) {
$value = array('year' => $value->format('Y'), 'month' => $value->format('m'));
}
$this->yearElement->setValue($value['year']);
$this->monthElement->setValue($value['month']);
}
示例3: setValue
/**
* {@inheritDoc}
*/
public function setValue($value)
{
if ($this->isMultiple()) {
if ($value instanceof \Traversable) {
$value = ArrayUtils::iteratorToArray($value);
} elseif (!$value) {
return parent::setValue([]);
} elseif (!is_array($value)) {
$value = (array) $value;
}
return parent::setValue(array_map(Locale::class . '::canonicalize', $value));
}
return parent::setValue(Locale::canonicalize($value));
}
示例4: setValue
/**
* {@inheritDoc}
*/
public function setValue($value)
{
$multiple = $this->getAttribute('multiple');
if (true === $multiple || 'multiple' === $multiple) {
if ($value instanceof \Traversable) {
$value = ArrayUtils::iteratorToArray($value);
} elseif ($value == null) {
return parent::setValue(array());
} elseif (!is_array($value)) {
$value = (array) $value;
}
return parent::setValue(array_map(array($this->getProxy(), 'getValue'), $value));
}
return parent::setValue($this->getProxy()->getValue($value));
}
示例5: setValue
/**
* @param string|array|\ArrayAccess|PhpDateTime $value
* @throws \Zend\Form\Exception\InvalidArgumentException
* @return void|\Zend\Form\Element
*/
public function setValue($value)
{
if (is_string($value)) {
try {
$value = new PhpDateTime($value);
} catch (Exception $e) {
throw new InvalidArgumentException('Value should be a parsable string or an instance of DateTime');
}
}
if ($value instanceof PhpDateTime) {
$value = array('year' => $value->format('Y'), 'month' => $value->format('m'), 'day' => $value->format('d'));
}
$this->yearElement->setValue($value['year']);
$this->monthElement->setValue($value['month']);
$this->dayElement->setValue($value['day']);
}
示例6: initSharedUsersSelect
public function initSharedUsersSelect($uploadId)
{
$upload = $this->uploadTable->getById($uploadId);
$sharedUsers = $this->uploadTable->getSharedUsers($uploadId);
foreach ($sharedUsers as $sharedUser) {
$userSelected[] = $sharedUser->user_id;
}
// \Zend\Debug\Debug::dump($sharedUsers);
$users = $this->userTable->fetchAll();
foreach ($users as $user) {
if ($user->getId() != $upload->getUserId()) {
$usersOptions[$user->getId()] = $user->getEmail();
}
}
$options = array('label' => 'Пользователи', 'value_options' => $usersOptions, 'disable_inarray_validator' => true, "attributes" => array("value" => 0));
$select = new Element\Select('shared_user_ids');
$select->setOptions($options);
$select->setValue($userSelected);
$select->setAttribute('multiple', 'multiple');
$this->add($select);
}
示例7: load
/**
* Load Image cropper prevalue editor
*
* @return string
*/
public function load()
{
$config = $this->getConfig();
$resizeOption = new Element\Select('resize_option');
$resizeOption->setValue(empty($config['resize_option']) ? 'auto' : $config['resize_option'])->setAttribute('class', 'form-control')->setAttribute('id', 'resize-option')->setLabel('Resize option')->setLabelAttributes(array('class' => 'col-lg-2'))->setValueOptions(array('auto' => 'auto', 'crop' => 'crop'));
$backgroundOption = new Element\Text('background');
$backgroundOption->setValue(empty($config['background']) ? '' : $config['background'])->setAttribute('class', 'form-control')->setAttribute('id', 'background')->setLabel('Background color')->setLabelAttributes(array('class' => 'col-lg-2'));
$mimeList = new Element\MultiCheckbox('mime_list');
$mimeList->setAttribute('class', 'input-checkbox')->setLabel('Mime list')->setLabelAttributes(array('class' => 'col-lg-2'));
$array = array('image/gif', 'image/jpeg', 'image/png');
$options = array();
foreach ($array as $mime) {
$options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($config['mime_list']) ? array() : $config['mime_list']) ? false : true);
}
$mimeList->setValueOptions($options);
$sizeElements = array();
$idx = 0;
if (!empty($config['size'])) {
foreach ($config['size'] as $idx => $size) {
$elementSizeName = new Element\Text('size[' . $idx . '][name]');
$elementSizeName->setValue($size['name'])->setAttribute('class', 'form-control')->setAttribute('id', 'name' . $idx)->setLabel('Name');
$elementWidth = new Element\Text('size[' . $idx . '][width]');
$elementWidth->setValue($size['width'])->setAttribute('class', 'form-control')->setAttribute('id', 'width' . $idx)->setLabel('Width');
$elementHeight = new Element\Text('size[' . $idx . '][height]');
$elementHeight->setValue($size['height'])->setAttribute('class', 'form-control')->setAttribute('id', 'height' . $idx)->setLabel('Height');
$sizeElements[] = array($elementSizeName, $elementWidth, $elementHeight);
}
$idx++;
}
$elementSizeName = new Element\Text('size[#{idx}][name]');
$elementSizeName->setAttribute('id', 'name#{idx}')->setAttribute('class', 'form-control')->setLabel('Name');
$elementWidth = new Element\Text('size[#{idx}][width]');
$elementWidth->setLabel('Width')->setAttribute('class', 'form-control')->setAttribute('id', 'width#{idx}');
$elementHeight = new Element\Text('size[#{idx}][height]');
$elementHeight->setLabel('Height')->setAttribute('class', 'form-control')->setAttribute('id', 'height#{idx}');
$template = array($elementSizeName, $elementWidth, $elementHeight);
return $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('elements' => array('resize-option' => $resizeOption, 'background' => $backgroundOption, 'mime' => $mimeList, 'size' => $sizeElements, 'size-template' => $template)));
}
示例8: __construct
public function __construct(EntityManager $em, OrmPublicador $publicador = null, OrmLogin $orm = null)
{
parent::__construct("formLogin");
// var_dump($option);
// exit();
/*
* txtID
*/
$txtId = new Element\Hidden("id");
/*
* txtNome
*/
$txtEmail = new Element\Email("email");
$txtEmail->setAttributes(array('class' => 'form-control', 'placeholder' => 'Nome do Grupo', 'data-parsley-trigger' => 'change', 'required' => 'true'));
/*
* txtSenha
*/
$txtSenha = new Element\Password("senha");
$txtSenha->setAttributes(array('id' => "senha", 'class' => 'form-control', 'placeholder' => 'Nome do Grupo', 'required' => 'true', "data-parsley-trigger" => "change", "data-parsley-length" => "[6, 20]"));
/*
* txtSenhaConfirma
*/
$txtSenhaConfirma = new Element\Password("senhaconfirmar");
$txtSenhaConfirma->setAttributes(array('class' => 'form-control', 'placeholder' => 'Nome do Grupo', 'required' => 'true', "data-parsley-trigger" => "change", "data-parsley-equalto" => "#senha"));
/*
* cmbPublicador
*/
$dao = $em->getRepository('Stj\\Entity\\OrmPublicador');
if (empty($publicador)) {
$lista = $dao->findAll();
} else {
$lista = $dao->ListALLWhere($publicador->getGrupo()->getCongregacao()->getId());
}
$option = array();
foreach ($lista as $key => $value) {
$publicador = new OrmPublicador();
$publicador = $value;
$option[$publicador->getId()] = $publicador->getNome();
}
$cmbPublicador = new Element\Select('publicador');
$cmbPublicador->setValueOptions($option);
$cmbPublicador->setEmptyOption("Selecionar");
$cmbPublicador->setAttributes(array('class' => 'chosen-select', 'style' => 'width:175px;', 'required' => 'true'));
/*
* cmbNivel
*/
$dao = $em->getRepository('Stj\\Entity\\OrmNivel');
$lista = $dao->ListALL(FALSE);
$option = array();
foreach ($lista as $key => $value) {
$nivel = new OrmNivel();
$nivel = $value;
$option[$nivel->getId()] = $nivel->getNome();
}
$cmbNivel = new Element\Select('nivel');
$cmbNivel->setValueOptions($option);
$cmbNivel->setEmptyOption("Selecionar");
$cmbNivel->setAttributes(array('class' => 'chosen-select', 'style' => 'width:175px;', 'required' => 'true'));
/*
* Itoken
*/
$iToken = new Element\Csrf("iToken");
/*
* btnSalvar
*/
$btnSalvar = new Element\Button('salvar');
$btnSalvar->setAttributes(array('class' => 'btn btn-darkgray btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* btnVoltar
*/
$btnVoltar = new Element\Button('voltar');
$btnVoltar->setAttributes(array('class' => 'btn btn-blue btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* Preencher Componentes
*/
if ($orm != null) {
$txtId->setValue($orm->getId());
$txtEmail->setValue($orm->getEmail());
$cmbPublicador->setValue($orm->getPublicador()->getId());
$cmbNivel->setValue($orm->getNivel()->getId());
}
// Adiciona componetes no form
$this->add($txtId);
$this->add($txtEmail);
$this->add($txtSenha);
$this->add($txtSenhaConfirma);
$this->add($cmbPublicador);
$this->add($cmbNivel);
$this->add($iToken);
$this->add($btnSalvar);
$this->add($btnVoltar);
$this->setAttributes(array('id' => 'form', 'data-parsley-validate' => NULL));
}
示例9: addProperty
/**
* Add property sub form
*
* @param mixed $property \Gc\Property\Model|array
*
* @return DocumentType
*/
public function addProperty($property)
{
if (!is_array($property) and !$property instanceof Property\Model) {
return $this;
}
$fieldsets = $this->getProperties();
$name = new Element\Text('name');
$identifier = new Element('identifier');
$tab = new Element\Select('tab');
$tab->setAttribute('class', 'select-tab')->setValueOptions(array());
$datatype = new Element\Select('datatype');
$datatype->setAttribute('class', 'select-datatype')->setValueOptions($this->datatypeCollection->getSelect());
$description = new Element\Text('description');
$required = new Element\Checkbox('required');
$required->setCheckedValue('1')->setAttribute('id', 'required')->setAttribute('class', 'input-checkbox');
$propertyId = new Element\Hidden('property_id');
if ($property instanceof Property\Model) {
$name->setValue($property->getName());
$identifier->setValue($property->getIdentifier());
$tab->setValue($property->getTabId());
$datatype->setValue($property->getDatatypeId());
$description->setValue($property->getDescription());
$required->setValue((string) $property->isRequired());
$propertyId->setValue($property->getId());
$propertyFieldsetName = $property->getId();
} else {
$name->setValue($property['name']);
$identifier->setValue($property['identifier']);
$tab->setValue($property['tab']);
$datatype->setValue($property['datatype']);
$description->setValue($property['description']);
$required->setValue((string) (!empty($property['isRequired'])));
$propertyId->setValue(str_replace('property', '', $property['id']));
$propertyFieldsetName = $property['id'];
}
$propertyForm = new FieldSet($propertyFieldsetName);
$propertyForm->add($propertyId);
$propertyForm->add($name);
$propertyForm->add($identifier);
$propertyForm->add($tab);
$propertyForm->add($datatype);
$propertyForm->add($description);
$propertyForm->add($required);
$fieldsets->add($propertyForm);
$this->getInputFilter()->get('properties')->add(array('type' => 'Zend\\InputFilter\\InputFilter', 'name' => array('name' => 'name', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'identifier' => array('name' => 'identifier', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'regex', 'options' => array('pattern' => parent::IDENTIFIER_PATTERN)))), 'tab' => array('name' => 'tab', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'datatype' => array('name' => 'datatype', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'description' => array('name' => 'description', 'required' => false, 'allow_empty' => true), 'required' => array('name' => 'required', 'required' => false, 'allow_empty' => true)), $propertyFieldsetName);
return $this;
}
示例10: testCanMarkOptionsAsSelectedWhenEmptyOptionOrZeroValueSelected
public function testCanMarkOptionsAsSelectedWhenEmptyOptionOrZeroValueSelected()
{
$element = new SelectElement('foo');
$element->setEmptyOption('empty');
$element->setValueOptions(array(0 => 'label0', 1 => 'label1'));
$element->setValue('');
$markup = $this->helper->render($element);
$this->assertContains('<option value="" selected="selected">empty</option>', $markup);
$this->assertContains('<option value="0">label0</option>', $markup);
$element->setValue('0');
$markup = $this->helper->render($element);
$this->assertContains('<option value="">empty</option>', $markup);
$this->assertContains('<option value="0" selected="selected">label0</option>', $markup);
}
示例11: getRepeatFieldset
/**
* Builds repeat fieldset and returns it.
*
* @return Fieldset
*/
public function getRepeatFieldset()
{
$repeatFieldset = new Fieldset('repeat');
// Picker field
$picker = new Element\Select('picker');
$picker->setLabel('Repeat');
$picker->setAttributes(array('class' => 'form-control repeat', 'autocomplete' => 'off'));
$picker->setValueOptions($this->_repeatOptions);
$picker->setValue(self::DAILY);
$repeatFieldset->add($picker);
// Attach "child" fieldsets
$repeatFieldset->add($this->getRepeatWeeklyFieldset());
$repeatFieldset->add($this->getRepeatMonthlyFieldset());
$repeatFieldset->add($this->getRepeatYearlyFieldset());
return $repeatFieldset;
}
示例12: __construct
public function __construct(EntityManager $em, OrmPublicador $tipoPrivilegio = null, OrmPrivilegios $orm = null)
{
parent::__construct("formPrivilegios");
// var_dump($option);
// exit();
/*
* txtID
*/
$txtId = new Element\Hidden("id");
/*
* txtNome
*/
$txtDataInicio = new Element\Text("dataInicio");
$txtDataInicio->setAttributes(array('class' => 'form-control', 'placeholder' => 'XX/XX/XXXX', 'max-length' => '10', 'required' => 'true'));
$txtDataTermino = new Element\Text("dataTermino");
$txtDataTermino->setAttributes(array('class' => 'form-control', 'placeholder' => 'XX/XX/XXXX', 'max-length' => '10'));
/*
* cmbPublicador
*/
$dao = $em->getRepository('Stj\\Entity\\OrmPublicador');
if (empty($tipoPrivilegio)) {
$lista = $dao->findAll();
} else {
$lista = $dao->ListALLWhere($tipoPrivilegio->getId());
}
$option = array();
foreach ($lista as $key => $value) {
$tipoPrivilegio = new OrmPublicador();
$tipoPrivilegio = $value;
$option[$tipoPrivilegio->getId()] = $tipoPrivilegio->getNome();
}
$cmbPublicador = new Element\Select('publicador');
$cmbPublicador->setValueOptions($option);
$cmbPublicador->setEmptyOption("Selecionar");
$cmbPublicador->setAttributes(array('class' => 'chosen-select', 'style' => 'width:175px;', 'required' => 'true'));
/*
* cmbPrivilegio
*/
$dao = $em->getRepository('Stj\\Entity\\OrmTipoPrivilegios');
$lista = $dao->findAll();
$option = array();
foreach ($lista as $key => $value) {
$tipoPrivilegio = new OrmTipoPrivilegios();
$tipoPrivilegio = $value;
$option[$tipoPrivilegio->getId()] = $tipoPrivilegio->getNome();
}
$cmbPrivilegio = new Element\Select('privilegio');
$cmbPrivilegio->setValueOptions($option);
$cmbPrivilegio->setEmptyOption("Selecionar");
$cmbPrivilegio->setAttributes(array('class' => 'chosen-select', 'style' => 'width:175px;', 'required' => 'true'));
/*
* Itoken
*/
$iToken = new Element\Csrf("iToken");
/*
* btnSalvar
*/
$btnSalvar = new Element\Button('salvar');
$btnSalvar->setAttributes(array('class' => 'btn btn-darkgray btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* btnVoltar
*/
$btnVoltar = new Element\Button('voltar');
$btnVoltar->setAttributes(array('class' => 'btn btn-blue btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* Preencher Componentes
*/
if ($orm != null) {
$txtId->setValue($orm->getId());
$txtDataInicio->setValue($orm->getDataInicio() != "" ? $orm->getDataInicio()->format('d/m/Y') : "");
$txtDataTermino->setValue($orm->getDataTermino() != "" ? $orm->getDataTermino()->format('d/m/Y') : "");
$cmbPrivilegio->setValue($orm->getTipoPrivilegio()->getId());
$cmbPublicador->setValue($orm->getPublicador()->getId());
}
// Adiciona componetes no form
$this->add($txtId);
$this->add($txtDataInicio);
$this->add($txtDataTermino);
$this->add($cmbPublicador);
$this->add($cmbPrivilegio);
$this->add($iToken);
$this->add($btnSalvar);
$this->add($btnVoltar);
$this->setAttributes(array('id' => 'form', 'data-parsley-validate' => NULL));
}
示例13: __construct
public function __construct(EntityManager $em, $publicador = null, OrmGrupo $orm = null)
{
parent::__construct("formGrupo");
$dao = $em->getRepository('Stj\\Entity\\OrmCongregacao');
$lista = $dao->findAll();
$option = array();
foreach ($lista as $key => $value) {
$congregacao = new OrmCongregacao();
$congregacao = $value;
$option[$congregacao->getId()] = $congregacao->getNome();
}
// var_dump($option);
// exit();
/*
* txtID
*/
$txtId = new Element\Hidden("id");
/*
* txtNome
*/
$txtNome = new Element\Text("nome");
$txtNome->setAttributes(array('class' => 'form-control', 'placeholder' => 'Nome do Grupo', 'data-parsley-trigger' => 'change', 'pattern' => '^[aA-zZ0-9]+((\\s[aA-zZ0-9]+)+)?$', 'required' => 'true'));
/*
* cmbCongregacao
*/
$cmbCongregacao = new Element\Select('congregacao');
$cmbCongregacao->setValueOptions($option);
$cmbCongregacao->setEmptyOption("Escolha a congregação");
$cmbCongregacao->setAttributes(array('class' => 'chosen-select', 'style' => 'width:140px;', 'required' => 'true'));
/*
* txtCep
*/
$txtCep = new Element\Text("cep");
$txtCep->setAttributes(array('class' => 'form-control', 'placeholder' => 'XXXXXXXX', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]{2}[0-9]{3}[0-9]{3}$/', 'max-length' => '8'));
/*
* txtNumero
*/
$txtNumero = new Element\Text("numero");
$txtNumero->setAttributes(array('class' => 'form-control', 'placeholder' => 'Numero', 'data-parsley-trigger' => 'change', 'pattern' => '/^[0-9]+$/', 'max-length' => '6'));
/*
* txtLogradouro
*/
$txtLogradouro = new Element\Text("logradouro");
$txtLogradouro->setAttributes(array('class' => 'form-control', 'placeholder' => 'Ex: Rua, Avenida, Travessa...'));
/*
* txtComplemento
*/
$txtComplemento = new Element\Text("complemento");
$txtComplemento->setAttributes(array('class' => 'form-control', 'placeholder' => 'Ex: Rua, Avenida, Travessa...'));
/*
* txtBairro
*/
$txtBairro = new Element\Text("bairro");
$txtBairro->setAttributes(array('class' => 'form-control'));
/*
* txtCidade
*/
$txtCidade = new Element\Text("cidade");
$txtCidade->setAttributes(array('class' => 'form-control'));
/*
* txtUf
*/
$txtUf = new Element\Text("uf");
$txtUf->setAttributes(array('class' => 'form-control', 'max-length' => '2'));
/*
* Itoken
*/
$iToken = new Element\Csrf("iToken");
/*
* btnSalvar
*/
$btnSalvar = new Element\Button('salvar');
$btnSalvar->setAttributes(array('class' => 'btn btn-darkgray btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* btnVoltar
*/
$btnVoltar = new Element\Button('voltar');
$btnVoltar->setAttributes(array('class' => 'btn btn-blue btn-ef btn-ef-4 btn-ef-4c mb-10', 'type' => 'button'));
/*
* Preencher Componentes
*/
if ($orm != null) {
$txtId->setValue($orm->getId());
$txtNome->setValue($orm->getNome());
$cmbCongregacao->setValue($orm->getCongregacao()->getId());
$txtCep->setValue($orm->getCep());
$txtNumero->setValue($orm->getNumero());
$txtLogradouro->setValue($orm->getLogradouro());
$txtComplemento->setValue($orm->getComplemento());
$txtBairro->setValue($orm->getBairro());
$txtCidade->setValue($orm->getCidade());
$txtUf->setValue($orm->getUf());
}
// Adiciona componetes no form
$this->add($txtId);
$this->add($txtNome);
if (empty($publicador)) {
$this->add($cmbCongregacao);
}
$this->add($txtCep);
//.........这里部分代码省略.........
示例14: setValue
/**
* {@inheritDoc}
*/
public function setValue($value)
{
return parent::setValue($this->getProxy()->getValue($value));
}
示例15: setValue
/**
* @param string|int $value
* @return self
*/
public function setValue($value)
{
$this->insertSelectedClientIfRequired($value);
return parent::setValue($value);
}