[更新]:2019/06/24-23; 28
上载带有表单的文件时,遇到以下错误:
此值应为字符串类型
表单构建器设置FileType为:
FormType
class DocumentType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
/** @var Document $salle */
$document=$options['data']; //Unused for now
$dataRoute=$options['data_route']; //Unused for now
$builder->add('nom')
->add('description')
->add('fichier', FileType::class, array(
//'data_class' is not the problem, tested without it.
//see comments if you don't know what it does.
'data_class'=>null,
'required'=>true,
))
->add('isActif', null, array('required'=>false));
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults([
'data_class'=>Document::class,
'data_route'=>null,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
而且我的getter和setter没有类型提示以确保UploadedFile::__toString()不会被调用:
Entity
class Document { …Run Code Online (Sandbox Code Playgroud) 由于某些原因,我不知道Apache崩溃了。
这是崩溃时的apache日志:
[Sat Jun 02 02:38:05.196006 2018] [mpm_prefork:emerg] [pid 1122] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.196006 2018] [mpm_prefork:emerg] [pid 1116] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.198767 2018] [mpm_prefork:emerg] [pid 1115] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.199523 2018] [mpm_prefork:emerg] [pid 3924] (43)Identifier removed: AH00144: couldn't grab the accept mutex
[Sat Jun 02 02:38:05.204189 2018] [mpm_prefork:emerg] [pid 1937] (43)Identifier removed: AH00144: couldn't grab the …Run Code Online (Sandbox Code Playgroud) 我正在尝试将实体转换为关联数组。
看来该方法toArray()不适用于实体对象。
阅读 Symfony 文档,看来我应该使用SerializerInterface.
启用它后,我似乎找不到正确的语法将我的实体转换为关联数组。
有人可以纠正我的代码吗?
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\SerializerInterface;
// -----------------------
public function salleAction(Request $request, Projet $projet, SerializerInterface $serializer) {
return this->json(array(
'projet'=>$serializer->serialize($projet, new ObjectNormalizer())
));
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我收到此错误消息
警告:isset 或空中的偏移类型非法
如果我替换new ObjectNormalizer()为'jsons',我将收到下一条错误消息:
序列化“AppBundle\Entity\Projet”类的对象时检测到循环引用(配置限制:1)
为了从ManyToOne - OneToMany关系的反面编辑数据,并避免获取整个表的内容,我想从ID列表中获取数据。
虽然这行得通,
$data=array();
foreach($idList as $id) {
array_push($data, $em->getRepository(Entity::class)->findBy(array('id', $id)));
}
Run Code Online (Sandbox Code Playgroud)
它将执行与ID一样多的查询。在存储库中进行自己的查询之前,我想知道是否可以将多个ID与一起使用findBy。
如果有可能,我该怎么办?
symfony ×3
symfony-3.4 ×2
apache2 ×1
apache2.4 ×1
doctrine-orm ×1
symfony4 ×1
ubuntu ×1
ubuntu-18.04 ×1