dtuzjzs3853 2018-09-11 06:30
浏览 83
已采纳

在传递给表单参数的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.

  • 写回答

1条回答 默认 最新

  • doufangxian4985 2018-09-11 09:35
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?