當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Form::isValidName方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\Form::isValidName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::isValidName方法的具體用法?PHP Form::isValidName怎麽用?PHP Form::isValidName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\Form的用法示例。


在下文中一共展示了Form::isValidName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addChoice

 /**
  * Adds a new choice.
  *
  * @param array $bucketForPreferred The bucket where to store the preferred
  *                                  view objects.
  * @param array $bucketForRemaining The bucket where to store the
  *                                  non-preferred view objects.
  * @param mixed $choice The choice to add.
  * @param string $label The label for the choice.
  * @param array $preferredChoices The preferred choices.
  */
 protected function addChoice(&$bucketForPreferred, &$bucketForRemaining, $choice, $label, array $preferredChoices)
 {
     $index = $this->createIndex($choice);
     if ('' === $index || null === $index || !Form::isValidName((string) $index)) {
         throw new InvalidConfigurationException('The index "' . $index . '" created by the choice list is invalid. It should be a valid, non-empty Form name.');
     }
     $value = $this->createValue($choice);
     if (!is_string($value)) {
         throw new InvalidConfigurationException('The value created by the choice list is of type "' . gettype($value) . '", but should be a string.');
     }
     $view = new ChoiceView($value, $label);
     $this->choices[$index] = $this->fixChoice($choice);
     $this->values[$index] = $value;
     if ($this->isPreferred($choice, $preferredChoices)) {
         $bucketForPreferred[$index] = $view;
     } else {
         $bucketForRemaining[$index] = $view;
     }
 }
開發者ID:rouffj,項目名稱:symfony,代碼行數:30,代碼來源:ChoiceList.php

示例2: addChoice

 /**
  * Adds a new choice.
  *
  * @param array $bucketForPreferred The bucket where to store the preferred
  *                                  view objects.
  * @param array $bucketForRemaining The bucket where to store the
  *                                  non-preferred view objects.
  * @param mixed $choice The choice to add.
  * @param string $label The label for the choice.
  * @param array $preferredChoices The preferred choices.
  */
 protected function addChoice(&$bucketForPreferred, &$bucketForRemaining, $choice, $label, array $preferredChoices)
 {
     $index = $this->createIndex($choice);
     if ('' === $index || null === $index || !Form::isValidName((string) $index)) {
         throw new InvalidConfigurationException('The choice list index "' . $index . '" is invalid. Please set the choice field option "index_generation" to ChoiceList::GENERATE.');
     }
     $value = $this->createValue($choice);
     if (!is_scalar($value)) {
         throw new InvalidConfigurationException('The choice list value of type "' . gettype($value) . '" should be a scalar. Please set the choice field option "value_generation" to ChoiceList::GENERATE.');
     }
     // Always store values as strings to facilitate comparisons
     $value = $this->fixValue($value);
     $view = new ChoiceView($value, $label);
     $this->choices[$index] = $this->fixChoice($choice);
     $this->values[$index] = $value;
     if ($this->isPreferred($choice, $preferredChoices)) {
         $bucketForPreferred[$index] = $view;
     } else {
         $bucketForRemaining[$index] = $view;
     }
 }
開發者ID:nicodmf,項目名稱:symfony,代碼行數:32,代碼來源:ChoiceList.php


注:本文中的Symfony\Component\Form\Form::isValidName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。