0

在我的子类中显示对象时出现问题。创建对象后,它被正确插入到数据库中,但在显示时会导致错误。

以下是继承链接:

  • 用户
  • 抽象客户端扩展用户
  • Mairie 扩展客户

以下是涉及问题的页面代码:

  • 用户:
<?php

    namespace App\Entity;

    use App\Repository\UserRepository;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Security\Core\User\UserInterface;

    /**
     * @ORM\Entity(repositoryClass=UserRepository::class)
     * @ORM\Table(name="`user`")
     */

    class User implements UserInterface
    {

        /**
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         */
        private $id;

        /**
         * @ORM\Column(type="string", length=180, unique=true)
         */
        private $email;

        /**
         * @ORM\Column(type="json")
         */
        private $roles = [];

        /**
         * @var string The hashed password
         * @ORM\Column(type="string")
         */
        private $password;

        /**
         * @ORM\Column(type="string", length=255, nullable=true)
         */
        private $firstname;

        /**
         * @ORM\Column(type="string", length=255, nullable=true)
         */
        private $lastname;

        /**
         * @ORM\Column(type="string", length=255, nullable=true)
         */
        private $Entit;

(加上 getter 和 setter)

  • 客户 :
<?php

namespace App\Entity;

use App\Repository\ClientRepository;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\User;

/**
 * @ORM\Entity(repositoryClass=ClientRepository::class)
 */
Abstract class Client extends User
{


    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $adresse;

    /**
     * @ORM\Column(type="integer", nullable=true)
     */
    private $cp;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $ville;

    /**
     * @ORM\Column(type="string", length=15, nullable=true)
     */
    private $telephone;

(加上 getter 和 setter)

  • 麦莉:
<?php

namespace App\Entity;

use App\Entity\Client;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\MairieRepository;

/**
 * @ORM\Entity(repositoryClass=MairieRepository::class)
 */
class Mairie extends Client
{

}
  • 仪表板控制器:
<?php

namespace App\Controller\Admin;

use App\Entity\Elu;
use App\Entity\Client;
use App\Entity\Mairie;
use App\Entity\User;
use App\Entity\CdcColl;
use App\Entity\DashboardKibana;
use App\Repository\UserRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;

class DashboardController extends AbstractDashboardController
{

    protected $userRepository;
    
    public function __construct(
        UserRepository $userRepository
    )
    {
        $this->userRepository = $userRepository;
    }

    /**
     * @Route("/admin", name="admin")
     * @Security("is_granted('ROLE_ADMIN')")
     */
    public function index(): Response
    {
        return $this->render('admin/welcome.html.twig', 
        [
            'countUser' => $this->userRepository->countAllUser()
        ]
    );
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new()
            ->setTitle('SrciToZeendoc');
    }

    public function configureMenuItems(): iterable
    {
        yield MenuItem::linktoDashboard('Accueil', 'fa fa-home');
        yield MenuItem::linkToCrud('Dashboard', 'fas fa-chart-line', DashboardKibana::class); 
        yield MenuItem::linkToCrud('Mairie', 'fas fa-landmark', Mairie::class); 
        yield MenuItem::linkToCrud('Utilisateurs', 'fas fa-users', User::class);
        yield MenuItem::linkToCrud('Elu', 'fas fa-user', Elu::class);
        yield MenuItem::linkToCrud('Collectivité', 'fas fa-landmark', CdcColl::class);
        yield MenuItem::linkToUrl('Retour Site', 'fas fa-undo', '/');
    }
}
  • MairieCrudController :
<?php

namespace App\Controller\Admin;

use App\Entity\Mairie;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;

class MairieCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Mairie::class;
    }

    
    public function configureFields(string $pageName): iterable
    {
        return [
            TextField::new('email'),
            ChoiceField::new('roles', 'Roles')
            ->allowMultipleChoices()
            ->autocomplete()
            ->setChoices([  'User' => 'ROLE_USER',
                            'Mairie' => 'ROLE_MAIRIE',
                            'Admin' => 'ROLE_ADMIN',
                            'SuperAdmin' => 'ROLE_SUPER_ADMIN',
                            'Dashboard' => 'ROLE_DASHBOARD',
                            'Opendata' => 'ROLE_OPENDATA',
                            'IOT' => 'ROLE_IOT',
                            'Coffre Fort' => 'ROLE_COFFRE',
                            'Certificat SSL' => 'ROLE_SSL',
                            'GED' => 'ROLE_GED',
                            'Archivage' => 'ROLE_ARCHIVAGE',
                            'Statistiques' => 'ROLE_STATISTIQUES',
                            'Reporting' => 'ROLE_REPORTING',
                            'Cartographie' => 'ROLE_CARTOGRAPHIE'
                            ]
        )
        ->setPermission("ROLE_SUPER_ADMIN"),
            TextField::new('Password')->hideOnIndex(),
            TextField::new('Firstname'),
            TextField::new('Lastname'),
            TextField::new('adresse'),
            TextField::new('cp'),
            TextField::new('ville'),
            TextField::new('telephone')           
        ];
    }
  
}

这是获得的错误:

An exception occurred while executing 'SELECT u0_.id AS id_0, u0_.email AS email_1, u0_.roles AS roles_2, u0_.password AS password_3, u0_.firstname AS firstname_4, u0_.lastname AS lastname_5, u0_.entit AS entit_6, c1_.adresse AS adresse_7, c1_.cp AS cp_8, c1_.ville AS ville_9, c1_.telephone AS telephone_10 FROM mairie m2_ WHERE m2_.id IN (?)' with params [4]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'u0_.id' in 'field list'

据我了解,数据库中的插入很好,但是当涉及到显示时,它会在 Mairie 表中查找 id 列(仅存在于 User 类中)。

4

0 回答 0