하나의 양식 유형을 표시하려고하지만 사용자가 한 번에 패치 업로드를 업로드해야하는 경우가 있습니다. 30 개의 파일을 업로드하고 30 개의 페이지를 작성하십시오.양식 모음 오류
이The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class MS\CoreBundle\Entity\Photo. You can avoid this error by setting the "data_class" option to "MS\CoreBundle\Entity\Photo" or by adding a view transformer that transforms an instance of class MS\CoreBundle\Entity\Photo to scalar, array or an instance of \ArrayAccess.
갤러리 형식 코드는 다음과 같습니다 :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('photo', 'collection', array(
'type' => new PhotoType(),
'allow_add' => true,
'data_class' => 'MS\CoreBundle\Entity\Photo',
'prototype' => true,
'by_reference' => false,
));
}
사진 유형 코드는 다음과 같습니다
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', 'text', array('label' => "Title:", 'required' => true))
->add('File')
->add('album', 'entity', array(
'class' => 'MSCoreBundle:Album',
'property' => 'title',
'required' => true,
'query_builder' => function(EntityRepository $er)
{
return $er->createQueryBuilder('a')
->orderBy('a.title', 'ASC');
},
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'MS\CoreBundle\Entity\Photo',
));
}
내 컨트롤러 기능은 다음과 같습니다
public function newAction($count)
{
for($i = 1; $i <= $count; $i++) {
$entity = new Photo();
}
$form = $this->container->get('ms_core.gallery.form');
$form->setData($entity);
return array(
'entity' => $entity,
'form' => $form->createView()
);
}
이 오류를 수신하고
도움이 될 것입니다.