【问题标题】:Another "The class 'X' was not found in the chain configured namespaces另一个“在链配置的命名空间中找不到类'X'
【发布时间】:2013-11-25 21:03:42
【问题描述】:

我在持久化实体时收到此错误

另一个“在链配置的命名空间中找不到类'X'

在我将 Symfony 从 Windows 迁移到 Linux 之前,这曾经可以工作。

我的控制器:

public function SubscriptionHandlingAction(Request $request)
{

        if ($request->isMethod('POST')) 
        {

            $form = $this->createForm(new NewCustomer(), new Customer());
            $form->bind($request);

            if ($form->isValid()) 
            {

                // get the form data 
                $newcustomer = $form->getData();                    

                //get the date and set it in the entity
                $datecreation = new \DateTime(date('d-m-Y'));                     
                $newcustomer->setdatecreation($datecreation);

                //this works fine
                echo $newcustomer->getname();

                //persist the data
                $em = $this->getDoctrine()->getManager();
                $em->persist($newcustomer);
                $em->flush();


                return $this->render('NRtworksSubscriptionBundle:Subscription:subscription_success.html.twig');  

            }

当然,我的类实体是存在的,因为我可以基于它创建表单、对象等。 然而,这个实体不是“映射”的意思是教义:映射:信息没有给我任何东西(但我已经手动创建了相应的 sdl 表并放置了所有注释):

<?php

namespace NRtworks\SubscriptionBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;


/**
 * @ORM\Entity
 * @ORM\Table(name="Customer")
 */
class Customer
{

    /**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */

protected $idCustomer;

/**
 * @ORM\Column(type="string", length=100, unique = true)
 */

protected $name;  

 /**
 * @ORM\Column(type="string", length=50)
 */

protected $country;

 /**
 * @ORM\Column(type="datetime", nullable = false)
 */

protected $datecreation;

   /**
 * @ORM\Column(type="integer", length = 5, nullable = false)
 */

protected $admin_user;

//getter
// no need for that
// setter
// no need for that

}

?>

问题的任何提示?

非常感谢

【问题讨论】:

  • 你想和我们分享'X'的名字吗?换句话说,错误到底发生在哪里?另外,仔细查看类/命名空间中的大写字母,确保它们与类的目录和文件名相同。
  • 确定:在链配置的命名空间中找不到类 'NRtworks\SubscriptionBundle\Entity\Customer'
  • 如果这可以帮助:在 /home/eagle1/www/Symfony2/vendor/doctrine/common/ 中的 MappingException ::classNotFoundInNamespaces ('NRtworks\SubscriptionBundle\Entity\Customer', array()) lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php 在第 114 行

标签: symfony doctrine-orm flush persist


【解决方案1】:

您是否与多个实体管理器或连接一起工作?确保每个 em 与 config.yml 下的相应包匹配

doctrine:
  dbal:
    #connection info (driver/host/port/...)
  orm:
    entity_managers:
      manager_one:
      connection:  # your connection (eg: 'default:'
        mappings:
          YourRespectiveBundle: ~
          AnotherrespectiveBundle: ~

当我第一次使用多个 em 时,这让我大吃一惊。 否则,请检查 AppKernel.php 的捆绑包,并仔细检查数据库连接是否正确。

【讨论】:

    猜你喜欢
    • 2015-11-12
    • 2012-05-27
    • 1970-01-01
    • 2023-03-02
    • 1970-01-01
    • 2016-02-06
    • 2019-08-17
    • 2019-08-10
    • 2014-12-11
    相关资源
    最近更新 更多