在传递给表单参数的bom中请求symfony中的错误
I got a table in data base ID, json, status and everything works in another table and in this one I can save, read but can not take the data from repository and pass to form. Look:
that's my SliderType Form
class SliderType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('status', ChoiceType::class, array(
'data' => $options['status'],
'choices' => array(
"Aktywna" => 1,
"Nieaktywna" => 0
),
'attr' => array(
'class' => 'form-control'
),
))
And here I need to pass from options resolver a status variable which is boolean, so in controller I done it look:
//tworzymy formularz
$form = $this->createForm(SliderType::class, $request, array(
.
.
'status' => $slider->getStatus,
te problem is that another variables works perfect if i add only this i thrown a error:
Cannot read index "status" from object of type "Symfony\Component\HttpFoundation\Request" because it doesn't implement \ArrayAccess.
Any Idea what is wrong here? and the funny thing is that I got another controller with another table (structure the same) and all works fine.
You are giving the HttpRequest
of symfony to the data of your form.
This is causing your issue
You should pass the entity which will be hydrated by the form. Give your slider entity to createForm
method second argument
$form = $this->createForm(SliderType::class, $slider, array(
'status' => $slider->getStatus));
Than you should tell the form to handle the request and extract data from request to hydrate your entity with your form.
$form->handleRequest($request);
You should read the form documentation