Skip to content

Instantly share code, notes, and snippets.

@tristanbes
Created May 29, 2012 15:19
Show Gist options
  • Save tristanbes/2829001 to your computer and use it in GitHub Desktop.
Save tristanbes/2829001 to your computer and use it in GitHub Desktop.
<?php
[...]
class Car
{
/**
* @ORM\OneToMany(targetEntity="Condition", mappedBy="Car", cascade={"all"}, orphanRemoval=true)
*/
private $conditions;
public function setConditions($conditions)
{
$this->conditions = $conditions;
}
public function getConditions()
{
return $this->conditions;
}
public function addCondition($condition)
{
$this->conditions->add($condition);
$condition->setCar($this);
}
public function removeCondition($condition)
{
$this->conditions->remove($condition);
}
<?php
[...]
$builder->add('conditions', 'collection', array(
'type' => new ConditionType(),
'allow_add' => true,
'single_control' => false,
'allow_delete' => true,
'show_legend' => false,
'prototype' => true,
'options' => array(
'data_class' => 'Condition',
'label_render' => false,
'required' => false,
'widget_control_group' => false
)
));
<?php
[...]
class Condition
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var integer $car
*
* @ORM\ManyToOne(targetEntity="Car", inversedBy="conditions")
*/
private $car;
[getters and setters]
}
<?php
class ConditionType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('name');
}
public function getName()
{
return 'condition';
}
public function getDefaultOptions()
{
return array('data_class' => '[...]\Condition');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment