我已经将实体字段类型添加到我正在使用的表单中,但是当我尝试设置preferred_choices时,我收到以下错误消息
警告:spl_object_hash()期望参数1为object,在/srv/www/amber/public_html/Symfony/vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php第98行中给出的字符串
你可以看到下面的代码
    $builder->add('candStatus', 'entity', array(
        'label' => 'Candidate Status', 
        'class' => 'AmberAtsBundle:SelCandStatus',
        'query_builder' => function(EntityRepository $er) {
            return $er->createQueryBuilder('sc')
            ->orderBy('sc.rank', 'ASC');
            },
         'property' => 'candStatus',
         'preferred_choices' => array('1'),
        ));
我是Symfony的新手,所以任何帮助都会受到赞赏
Chr*_*ian 10
这适用于Symfony 2.7:
$builder->add('license', 'entity', [
    'class' => 'CmfcmfMediaModule:License\LicenseEntity',
    'preferred_choices' => function (LicenseEntity $license) {
        return !$license->isOutdated();
    },
    // ...
])
preferred_choices 需要一个为每个实体调用的匿名函数,并且必须返回true或false,具体取决于它是否是首选.
| 归档时间: | 
 | 
| 查看次数: | 3837 次 | 
| 最近记录: |