Symfony\Component\Form\CollectionField::setData PHP Метод

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

public setData ( $collection )
    public function setData($collection)
    {
        if (!is_array($collection) && !$collection instanceof \Traversable) {
            throw new UnexpectedTypeException('The data passed to the CollectionField must be an array or a Traversable');
        }

        foreach ($this as $name => $field) {
            if (!$this->getOption('modifiable') || $name != '$$key$$') {
                $this->remove($name);
            }
        }

        foreach ($collection as $name => $value) {
            $this->add($this->newField($name, $name));
        }

        parent::setData($collection);
    }

Usage Example

 public function testResizedDownIfSubmittedWithLessDataAndModifiable()
 {
     $field = new CollectionField('emails', array('prototype' => new TestField(), 'modifiable' => true));
     $field->setData(array('*****@*****.**', '*****@*****.**'));
     $field->submit(array('*****@*****.**'));
     $this->assertTrue($field->has('0'));
     $this->assertFalse($field->has('1'));
     $this->assertEquals('*****@*****.**', $field[0]->getData());
     $this->assertEquals(array('*****@*****.**'), $field->getData());
 }
All Usage Examples Of Symfony\Component\Form\CollectionField::setData