I have this field in entity:
/**
* @ORM\Column(type="boolean")
*/
protected $done = 0;
In database it's tinyint(1)
. When I try to add it into a form:
$builder
->add('done', 'checkbox')
It throws an error:
Unable to transform value for property path "done": Expected a Boolean.
Huh? Isn't it boolean?
0 or 1 are not booleans. They are integers. Use true/false in your domain model.
/**
* @ORM\Column(type="boolean")
*/
protected $done = false;
thanks a lot for the solution but this didn't work for me. I use symfony 4. This is how I accomplished,
Entity,
/**
* @ORM\Column(type="boolean")
*/
protected $done = 0;
public function getDone(): ?bool
{
return $this->done;
}
public function setDone(?bool $done): self
{
$this->done = $done;
return $this;
}
FormType,
->add('done', CheckboxType::class, array(
'required' => false,
'value' => 1,
))
I needed to add use CheckboxType since I call the class. (use Symfony\Component\Form\Extension\Core\Type\CheckboxType;) If you run "php bin/console doctrine:migrations:diff" db will add tinyint(1) field
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With