我无法使我的多个复选框列表中的消息有效。我希望能够选择几个条目并删除/或将它们移动到垃圾邮件文件夹。我试图var_dump
(用于调试目的)内容data = $form->getData()
,表达式var_dump(data['id'])
时出现问题。像Symfony3:D的整个代码库一样打印(这对我来说完全出乎意料)我基于我的代码上
Build a form having a checkbox for each entity in a doctrine collection并使用Doctrine。
这是代码
class MessageEntitySelectByIdentityType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('id', EntityType::class, array(
'required' => false,
'class' => 'MonoDomainBundle:Message',
// 'property' => 'id',
'property_path' => '[id]', # in square brackets!
'multiple' => true,
'expanded' => true
));
}
public function setDefaultOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Message::class,
'csrf_protection' => false
));
}
}
public function mailboxAction(Request $request)
{
$user = $this->getDoctrine()->getManager()->getRepository('MonoDomainBundle:User')->find(1);
$collection = $this->getDoctrine()->getRepository(Message::class)->getMyInbox($user);
$form = $this
->createForm(
\Mono\DomainBundle\Form\MessageEntitySelectByIdentityType::class,
$collection
);
$form->add('spam', SubmitType::class);
$form->add('delete', SubmitType::class, ['label' => 'Trash']);
$form->handleRequest($request);
$this->addFlash('success', 'settings.simplified.general.text.success');
if ($form->isValid()) {
$data = $form['id']->getData();
var_dump($data);