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


PHP FormConfigInterface::getFormFactory方法代碼示例

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


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

示例1: add

 /**
  * {@inheritdoc}
  */
 public function add($child, $type = null, array $options = array())
 {
     if ($this->submitted) {
         throw new AlreadySubmittedException('You cannot add children to a submitted form');
     }
     if (!$this->config->getCompound()) {
         throw new LogicException('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
     }
     // Obtain the view data
     $viewData = null;
     // If setData() is currently being called, there is no need to call
     // mapDataToForms() here, as mapDataToForms() is called at the end
     // of setData() anyway. Not doing this check leads to an endless
     // recursion when initializing the form lazily and an event listener
     // (such as ResizeFormListener) adds fields depending on the data:
     //
     //  * setData() is called, the form is not initialized yet
     //  * add() is called by the listener (setData() is not complete, so
     //    the form is still not initialized)
     //  * getViewData() is called
     //  * setData() is called since the form is not initialized yet
     //  * ... endless recursion ...
     //
     // Also skip data mapping if setData() has not been called yet.
     // setData() will be called upon form initialization and data mapping
     // will take place by then.
     if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) {
         $viewData = $this->getViewData();
     }
     if (!$child instanceof FormInterface) {
         if (!is_string($child) && !is_int($child)) {
             throw new UnexpectedTypeException($child, 'string, integer or Symfony\\Component\\Form\\FormInterface');
         }
         if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {
             throw new UnexpectedTypeException($type, 'string or Symfony\\Component\\Form\\FormTypeInterface');
         }
         // Never initialize child forms automatically
         $options['auto_initialize'] = false;
         if (null === $type && null === $this->config->getDataClass()) {
             $type = 'Symfony\\Component\\Form\\Extension\\Core\\Type\\TextType';
         }
         if (null === $type) {
             $child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
         } else {
             $child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
         }
     } elseif ($child->getConfig()->getAutoInitialize()) {
         throw new RuntimeException(sprintf('Automatic initialization is only supported on root forms. You ' . 'should set the "auto_initialize" option to false on the field "%s".', $child->getName()));
     }
     $this->children[$child->getName()] = $child;
     $child->setParent($this);
     if (!$this->lockSetData && $this->defaultDataSet && !$this->config->getInheritData()) {
         $iterator = new InheritDataAwareIterator(new \ArrayIterator(array($child->getName() => $child)));
         $iterator = new \RecursiveIteratorIterator($iterator);
         $this->config->getDataMapper()->mapDataToForms($viewData, $iterator);
     }
     return $this;
 }
開發者ID:ayoah,項目名稱:symfony,代碼行數:61,代碼來源:Form.php

示例2: add

    /**
     * {@inheritdoc}
     */
    public function add($child, $type = null, array $options = array())
    {
        if ($this->bound) {
            throw new AlreadyBoundException('You cannot add children to a bound form');
        }

        if (!$this->config->getCompound()) {
            throw new Exception('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
        }

        // Obtain the view data
        $viewData = null;

        // If setData() is currently being called, there is no need to call
        // mapDataToForms() here, as mapDataToForms() is called at the end
        // of setData() anyway. Not doing this check leads to an endless
        // recursion when initializing the form lazily and an event listener
        // (such as ResizeFormListener) adds fields depending on the data:
        //
        //  * setData() is called, the form is not initialized yet
        //  * add() is called by the listener (setData() is not complete, so
        //    the form is still not initialized)
        //  * getViewData() is called
        //  * setData() is called since the form is not initialized yet
        //  * ... endless recursion ...
        if (!$this->lockSetData) {
            $viewData = $this->getViewData();
        }

        if (!$child instanceof FormInterface) {
            if (!is_string($child) && !is_int($child)) {
                throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormInterface');
            }

            if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {
                throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\FormTypeInterface');
            }

            if (null === $type) {
                $child = $this->config->getFormFactory()->createForProperty($this->config->getDataClass(), $child, null, $options);
            } else {
                $child = $this->config->getFormFactory()->createNamed($child, $type, null, $options);
            }
        }

        $this->children[$child->getName()] = $child;

        $child->setParent($this);

        if (!$this->lockSetData) {
            $this->config->getDataMapper()->mapDataToForms($viewData, array($child));
        }

        return $this;
    }
開發者ID:Robert-Xie,項目名稱:php-framework-benchmark,代碼行數:58,代碼來源:Form.php


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