我的FormType有问题。我想显示数据,并感谢querybuilder做出区分。当我用 - >调用我的方法时出现问题select(' t.nomVern')我有"警告:spl_object_hash()期望参数1是对象,字符串给出"作为错误消息。
我不明白为什么。
我的FormType ObservationType:
gimp-selection-bounds
我的存储库:
<?php
namespace ObservationBundle\Form;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Vich\UploaderBundle\Form\Type\VichImageType;
use ImportBundle\Repository\TaxrefRepository;
use ImportBundle\Entity\Taxref;
class ObservationType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('date', DateType::class, array(
'widget' => 'single_text',
'html5' => false,
'attr' => array(
'placeholder' => 'Choisir la date de l\'observation',
)
))
->add('latitude', TextType::class, array(
'attr' => array(
'placeholder' => 'Latitude ex : 31.85322'
)
))
->add('longitude', TextType::class, array(
'attr' => array(
'placeholder' => 'Longitude ex : 33.55555'
)
))
->add('nombre', IntegerType::class)
->add('imageFile', VichImageType::class, array(
'required' => false,
'allow_delete' => false, // not mandatory, default is true
'download_link' => false, // not mandatory, default is true
'attr' => array(
'placeholder' => 'Votre image'
)
))
->add('valide', HiddenType::class)
->add('commentaire', HiddenType::class)
->add('gpsAffiche', HiddenType::class)
->add('meteo', HiddenType::class)
->add('saison', HiddenType::class)
->add('typeSaisie', HiddenType::class)
->add('precipitation', HiddenType::class)
->add('periode', HiddenType::class)
->add('environnement', HiddenType::class)
->add('sensibilite', HiddenType::class)
->add('comportement', HiddenType::class)
->add('species', EntityType::class, array(
'label' => 'Espèce observée :',
'class' => 'ImportBundle\Entity\Taxref',
'choice_label' => 'nomVern',
'query_builder' => function(TaxrefRepository $qb){
return $qb->distinctTaxref();
}
))
;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'ObservationBundle\Entity\Observation'
));
}
/**
* @return string
*/
public function getBlockPrefix()
{
return 'observationbundle_observation';
}
}
提前感谢你的帮助,抱歉我的英文不好:/
答案 0 :(得分:0)
试试这部分代码
itemListElement.forEach(function(ele){
document.getElementById("bc").innerHTML = document.getElementbyId("bc").innerHTML + " > " + ele.item.name;
})
答案 1 :(得分:0)
我相信,既然你正在使用EntityType
,Symfony希望有一个对象数组,而你选择一个产生字符串数组的列。
您可以尝试选择一个整体:
return $this
->createQueryBuilder('t')
->select('t')
->distinct(true)
->orderBy('t.nomVern', 'ASC');
这有用吗?