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

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

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致