简体   繁体   English

在链配置的名称空间App \\ Entity中找不到类'App \\ Form \\ Database_InteractionType'

[英]The class 'App\Form\Database_InteractionType' was not found in the chain configured namespaces App\Entity

Hello i can't find the error when i try to delete something out of my database. 您好,当我尝试从数据库中删除某些内容时,我找不到错误。

It says that my namespace is wrong but i really cant find any issues. 它说我的名称空间是错误的,但是我真的找不到任何问题。

Here is the action im calling 这是即时通讯呼吁

   /**
     * @Route("/delete/{id}", name="delete")
     * @param $id
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
     */
    public function deleteById($id)
    {
        $em = $this->getDoctrine()->getManager();

        $entries = $em->getRepository(Database_InteractionType::class)->find($id);

        $em->remove($entries);
        $em->flush();

        return $this->redirectToRoute('show');
    }

Here is Entitiy and my Form. 这是实体和我的表格。 I have been looking at it for 2 hours straight and i cant seem to find the Iusse.. 我已经连续观察了2个小时,但似乎找不到Iusse ..

Entity: 实体:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\Database_InteractionRepository")
 */
class Database_Interaction
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

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

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

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getQuestion(): ?string
    {
        return $this->question;
    }

    public function setQuestion(string $question): self
    {
        $this->question = $question;

        return $this;
    }

    public function getAnswer(): ?string
    {
        return $this->answer;
    }

    public function setAnswer(string $answer): self
    {
        $this->answer = $answer;

        return $this;
    }
}

My Form: 我的表格:

<?php

namespace App\Form;

use App\Entity\Database_Interaction;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Database_InteractionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add(
                'question',
                TextType::class,
                [
                    'attr' => [
                        'placeholder' => 'Enter your Question',
                        'class' => 'form-control'
                    ],
                    'required' => true
                ]
            )
            ->add(
                'answer',
                TextType::class,
                [
                    'required' => true,
                    'attr' => [
                        'class' => 'form-control',
                        'placeholder' => 'Enter your Answer',
                    ]
                ]
            )
            ->add(
                'save',
                SubmitType::class,
                [
                    'attr' => [
                        'class' => 'btn btn-primary'
                    ]
                ]
            )
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Database_Interaction::class,
        ]);
    }
}

And my Repository if this is to any help.. 还有我的存储库,如果有帮助的话。

<?php

namespace App\Repository;

use App\Entity\Database_Interaction;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method Database_Interaction|null find($id, $lockMode = null, $lockVersion = null)
 * @method Database_Interaction|null findOneBy(array $criteria, array $orderBy = null)
 * @method Database_Interaction[]    findAll()
 * @method Database_Interaction[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class Database_InteractionRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, Database_Interaction::class);
    }

    /**
     * @param string $id
     * @return Database_Interaction|null
     */
    public function findById(string $id)
    {
        return $this->findOneBy(
            ['id' => $id]
        );
    }

    // /**
    //  * @return SubmitNew[] Returns an array of SubmitNew objects
    //  */
    /*
    public function findByExampleField($value)
    {
        return $this->createQueryBuilder('s')
            ->andWhere('s.exampleField = :val')
            ->setParameter('val', $value)
            ->orderBy('s.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
    */

    /*
    public function findOneBySomeField($value): ?SubmitNew
    {
        return $this->createQueryBuilder('s')
            ->andWhere('s.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}

If anyone could help me out I don't know where to look anymore... 如果有人可以帮助我,我将不知所措...

Thank you 谢谢

Look closely at this line: 仔细观察这一行:

$entries = $em->getRepository(Database_InteractionType::class)->find($id);

This refers to the form type class( App\\Form\\Database_InteractionType ) not your persisted entity class, which lives in App\\Entity namespace (the namespace it is looking in), this is why the error is produced. 这是指表单类型类( App\\Form\\Database_InteractionType ),而不是持久化的实体类,该类位于App\\Entity命名空间(它正在查找的命名空间)中,这就是产生错误的原因。 Forms do not have a repository, the related entity does. 表单没有存储库,相关实体则有。 Try this: 尝试这个:

$entries = $em->getRepository(Database_Interaction::class)->find($id);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在链配置的命名空间中找不到类“App\\Entity\\Users” - The class 'App\Entity\Users' was not found in the chain configured namespaces 在链配置的名称空间中找不到类“ App \\ Document \\ User” - The class 'App\Document\User' was not found in the chain configured namespaces 在链配置的命名空间 StudentsBundle\\Entity 中找不到类“ScheduleBundle\\Entity\\schedule” - The class 'ScheduleBundle\Entity\schedule' was not found in the chain configured namespaces StudentsBundle\Entity 在链配置的命名空间FOS \\ OAuthServerBundle \\ Document中找不到类&#39;OAuthBundle \\ Entity \\ Client&#39; - The class 'OAuthBundle\Entity\Client' was not found in the chain configured namespaces FOS\OAuthServerBundle\Document 在提交表单期间,在链配置的名称空间中找不到类&#39;Symfony \\ Component \\ Form \\ Form&#39; - The class 'Symfony\Component\Form\Form' was not found in the chain configured namespaces during Form Submission MappingException - 在链配置的命名空间 xxx 中找不到 class 'generalBundle\Entity\xxx' - 升级到 symfony flex - MappingException - The class 'generalBundle\Entity\xxx' was not found in the chain configured namespaces xxx - Upgrade to symfony flex Symfony 错误在链配置的命名空间 XXX 中找不到类 XXX - Symfony error The class XXX was not found in the chain configured namespaces XXX Symfony + Doctrine ODM“在链配置的名称空间CoreBundle / Document中找不到该类” - Symfony + Doctrine ODM “The class was not found in the chain configured namespaces CoreBundle/Document” 在链配置的名称空间\\ Document中找不到类&#39;Calendar \\ Document \\ Calendar&#39;? - class 'Calendar\Document\Calendar' was not found in the chain configured namespaces \Document? 在链配置的命名空间 XXX 中找不到类“Doctrine\\ORM\\EntityManager” - The class 'Doctrine\ORM\EntityManager' was not found in the chain configured namespaces XXX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM