Ik heb een webapp waarmee klanten beheerd kunnen worden. Om het een stuk dynamischer te maken, is het mogelijk om aangepaste velden in de database te kunnen zetten zodat deze per klant ingevuld kunnen worden. Dit is hoe het er globaal uitziet: (alleen de belangrijkste ORM annotations zijn weergegeven)
Customer:
<?php
class Customer
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private $firstname;
private $insertion;
private $lastname;
private $address;
private $city;
private $zipcode;
private $gender;
/**
* @ORM\OneToMany(targetEntity="PropertyValue", mappedBy="customer")
*/
private $propertyValues;
private $active;
}
?>
Property:
<?php
class Property
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private $name;
private $required;
/**
* @ORM\OneToMany(targetEntity="Value", mappedBy="property")
*/
private $values;
/**
* @ORM\OneToMany(targetEntity="PropertyValue", mappedBy="property")
*/
private $propertyValues;
private $type;
private $active;
}
?>PropertyValue:
<?php
class PropertyValue
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Customer", inversedBy="propertyValues")
* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", nullable=false)
*/
private $customer;
/**
* @ORM\ManyToOne(targetEntity="Property", inversedBy="propertyValues")
* @ORM\JoinColumn(name="property_id", referencedColumnName="id", nullable=false)
*/
private $property;
/**
* @ORM\ManyToOne(targetEntity="Value", inversedBy="propertyValues")
* @ORM\JoinColumn(name="value_id", referencedColumnName="id", nullable=true)
*/
private $referencedValue;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $value;
}
?>Ik heb een form class aangemaakt voor het aanpassen van klanten:
<?php
class CustomerType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstname')
->add('insertion')
->add('lastname')
->add('gender', 'choice', array(
'choices' => array(1 => 'Man', 2 => 'Vrouw'),
'expanded' => true,
'multiple' => false
))
->add('address')
->add('city')
->add('zipcode')
->add('propertyvalues', 'collection', array('type' => new PropertyValueType()));
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Customer'
));
}
public function getName()
{
return 'customer';
}
}
?>En dan de form class van PropertyValue:
<?php
class PropertyValueType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('value', 'text');
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\PropertyValue'
));
}
public function getName()
{
return 'propertyvalue';
}
}
?>Naar mijn idee moet het zo, maar ik krijg de volgende foutmelding en heb na een tijd Googelen nog steeds geen idee wat ik fout doe:
The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class AppBundle\Entity\PropertyValue. You can avoid this error by setting the "data_class" option to "AppBundle\Entity\PropertyValue" or by adding a view transformer that transforms an instance of class AppBundle\Entity\PropertyValue to scalar, array or an instance of \ArrayAccess.
Kan iemand me helpen? Bij voorbaat dank! :)