I am having trouble making my multiple checkboxes list of Messages work, i want to be able to select few entries and delete/or move them to spam folder, i get stuck while trying to var_dump (for debugging purposes) content of data = $form->getData() , expression var_dump(data['id']) Prints like entire codebase of Symfony3 :D (which was for me totally unexpected) i based my code on Build a form having a checkbox for each entity in a doctrine collection and use Doctrine. This is the code
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);
Aucun commentaire:
Enregistrer un commentaire