Home > Software design >  Illegal offset type with easyadmin choice field
Illegal offset type with easyadmin choice field

Time:07-16

I'm creating a easyadmin bundle. Nevertheless, I've got an error with a multiple choice (choice field). Indeed, when I add the choice field, i've got the following error:

Illegal offset type

Here is my code:

<?php

namespace App\Controller\Admin;

use App\Entity\Book;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;

class BookCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Book::class;
    }

    public function configureFields(string $pageName): iterable
    {
        return [
            TextField::new('title'),
            ChoiceField::new('categorie')->setChoices([
                'Roman' =>1,
                'Poésie' => 2,
                'Non fiction' =>3,
                'SF' => 4,
               
            ]),
            BooleanField::new('borrowed'),
           
        ];
    }

    
}

Any suggestion ? Thanks in advance :)

CodePudding user response:

I've just used the wrong field. Indeed, the right one was Association Field.

Here is my code :

public function configureFields(string $pageName): iterable
{
    return [
        TextField::new('title'),
        AssociationField::new('categorie'),
        BooleanField::new('borrowed'),
        AssociationField::new('user_id'),
       
    ];
}
  • Related