Symfony\Component\Form\Form::createView PHP Метод

createView() публичный Метод

Creates a view.
public createView ( Symfony\Component\Form\FormView $parent = null ) : Symfony\Component\Form\FormView
$parent Symfony\Component\Form\FormView The parent view
Результат Symfony\Component\Form\FormView The view
    public function createView(FormView $parent = null)
    {
        if (null === $parent && $this->parent) {
            $parent = $this->parent->createView();
        }

        $view = new FormView();

        $view->setParent($parent);

        $types = (array) $this->types;

        foreach ($types as $type) {
            $type->buildView($view, $this);

            foreach ($type->getExtensions() as $typeExtension) {
                $typeExtension->buildView($view, $this);
            }
        }

        $childViews = array();

        foreach ($this->children as $key => $child) {
            $childViews[$key] = $child->createView($view);
        }

        if (null !== $prototype = $view->get('prototype')) {
            $protoView = $prototype->getForm()->createView($view);
            $protoTypes = $protoView->get('types');
            $protoTypes[] = 'prototype';
            $childViews[$prototype->getName()] = $protoView
                ->set('types', $protoTypes)
                ->set('proto_id', $view->get('id').'_prototype');
            ;
        }

        $view->setChildren($childViews);

        foreach ($types as $type) {
            $type->buildViewBottomUp($view, $this);

            foreach ($type->getExtensions() as $typeExtension) {
                $typeExtension->buildViewBottomUp($view, $this);
            }
        }

        return $view;
    }

Usage Example

 /**
  * @param $page
  * @param null $template
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *
  * @throws \Exception
  */
 public function renderList($page, $template = null)
 {
     $user = $this->getUser();
     $tpl = null === $template ? $this->templatePath . 'list.html.twig' : $template;
     if ($this->filterForm) {
         $this->filterForm = $this->createForm($this->filterForm);
     }
     $qb = $this->buildFilterQuery();
     $paginator = $this->get('knp_paginator');
     $pagination = $paginator->paginate($qb->getQuery(), $page, $this->list_item_per_page, $this->defaultSortList);
     return $this->render($tpl, array('user' => $user, 'nbPerPage' => $this->list_item_per_page, 'page' => $page, 'form' => $this->filterForm ? $this->filterForm->createView() : null, 'baseRoute' => $this->baseRoute, 'entityName' => $this->entityName, 'list' => ['records' => $pagination, 'fields' => $this->listColumn, 'parameters' => $this->listConf, 'actions' => $this->listActions], 'actionsList' => $this->actionsList(), 'listTitle' => $this->listTitle));
 }
All Usage Examples Of Symfony\Component\Form\Form::createView