将数据库模式导入Symfony2后,Doctrine2配置文件'问题

时间:2011-11-14 07:03:20

标签: php xml symfony doctrine-orm configuration-files

编辑:新问题

我有一些新东西:

我很确定这是xml文件搞砸了。

以下是我的进展:

  1. 我制作了自己的数据库方案
  2. 我创建了数据库(sql脚本)
  3. 我反向设计了数据库
  4. 我修复了表之间的关联。
  5. 在我的XML conf存储库中: src / Creasixtine / AFBundle / Resources / config / doctrine / metadata / orm

    我有我的所有实体:

    Blobs.orm.xml    Lieu.orm.xml    Operationrre.orm.xml  Pn.orm.xml              Roles.orm.xml  Service.orm.xml  Typeoperationmaintenance.orm.xml
    Famille.orm.xml  Module.orm.xml  Outilsn.orm.xml       Rolepermission.orm.xml  Rre.orm.xml    Session.orm.xml  Utilisateur.orm.xml
    

    例如,这是Utilisateur的xml文件:

    <?xml version="1.0" encoding="utf-8"?>
    <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
    <entity name="Utilisateur" table="UTILISATEUR">
        <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>
        <id name="userid" type="integer" column="USERID">
          <generator strategy="IDENTITY"/>
        </id>
        <field name="userdatecreation" type="date" column="USERDATECREATION"/>
        <field name="userdatevalidation" type="date" column="USERDATEVALIDATION"/>
        <field name="usermail" type="string" column="USERMAIL" length="255"/>
        <field name="userpass" type="string" column="USERPASS" length="255"/>
        <field name="uservalide" type="boolean" column="USERVALIDE"/>
        <lifecycle-callbacks/>
      </entity>
    </doctrine-mapping>
    

    有了这个,我得到了:

      

    注意:未定义的索引:id /home/adrien/dev/air-france_alphanum/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php 1969行

    旧帖子

    我(很久以前)导入了数据库架构。

    我有一个Utilisateur实体/类。 我通过以下方式在Utilisateur表中成功创建了新录音:

    function newUser($login, $name, $mail, $pass)
        {
            $obj = new Utilisateur();
            $obj->setUsermail($mail);
            $obj->setUserpass($pass);
            $obj->setUserlogin($login);
            $obj->setUsername($name);
    
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($obj);
            $em->flush();
    
        }
    

    现在什么行不通:我想让现有用户进入数据库:

        $em = $this->container->get('doctrine')->getEntityManager();
        $rre_repository = $em->getRepository('GoogleAFBundle:Utilisateur');
        $users = $rre_repository->findAll();
    

    我得到一个例外:

    Notice: Undefined index: Google\AFBundle\Entity\Utilisateur in /home/adrien/dev/air-france_alphanum/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/AbstractFileDriver.php line 121
    

    这是Utilisateur类:

    <?php
    
    namespace Google\AFBundle\Entity;
    
    use Symfony\Tests\Component\Translation\String;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Google\AFBundle\Entity\Utilisateur
     *
     * @ORM\Table(name="UTILISATEUR")
     * @ORM\Entity
     */
    class Utilisateur
    {
        /**
         * @var integer $userid
         *
         * @ORM\Column(name="USERID", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $userid;
    
        /**
        * @var string $userlogin
        *
        * @ORM\Column(name="USERLOGIN", type="string", length=31, nullable=false)
        */
        private $userlogin;
    
        /**
        * @var string $username
        *
        * @ORM\Column(name="USERNAME", type="string", length=255, nullable=true)
        */
        private $username;
    
        /**
         * @var date $userdatecreation
         *
         * @ORM\Column(name="USERDATECREATION", type="date", nullable=true)
         */
        private $userdatecreation;
    
        /**
         * @var date $userdatevalidation
         *
         * @ORM\Column(name="USERDATEVALIDATION", type="date", nullable=true)
         */
        private $userdatevalidation;
    
        /**
         * @var string $usermail
         *
         * @ORM\Column(name="USERMAIL", type="string", length=255, nullable=true)
         */
        private $usermail;
    
        /**
         * @var string $userpass
         *
         * @ORM\Column(name="USERPASS", type="string", length=255, nullable=true)
         */
        private $userpass;
    
        /**
         * @var boolean $uservalide
         *
         * @ORM\Column(name="USERVALIDE", type="boolean", nullable=true)
         */
        private $uservalide;
    
        /**
        * @ORM\OneToMany(targetEntity="Utilroles", mappedBy="userid")
        */
        private $utilroles;
    
        /**
        * @ORM\OneToMany(targetEntity="Connexion", mappedBy="userid")
        */
        private $connexions;
    
        /**
         * Get userid
         *
         * @return integer
         */
        public function getUserid()
        {
            return $this->userid;
        }
    
        /**
         * Set userdatecreation
         *
         * @param date $userdatecreation
         */
        public function setUserdatecreation($userdatecreation)
        {
            $this->userdatecreation = $userdatecreation;
        }
    
        /**
         * Get userdatecreation
         *
         * @return date
         */
        public function getUserdatecreation()
        {
            return $this->userdatecreation;
        }
    
        /**
         * Set userdatevalidation
         *
         * @param date $userdatevalidation
         */
        public function setUserdatevalidation($userdatevalidation)
        {
            $this->userdatevalidation = $userdatevalidation;
        }
    
        /**
         * Get userdatevalidation
         *
         * @return date
         */
        public function getUserdatevalidation()
        {
            return $this->userdatevalidation;
        }
    
        /**
         * Set usermail
         *
         * @param string $usermail
         */
        public function setUsermail($usermail)
        {
            $this->usermail = $usermail;
        }
    
        /**
         * Get usermail
         *
         * @return string
         */
        public function getUsermail()
        {
            return $this->usermail;
        }
    
        /**
         * Set userpass
         *
         * @param string $userpass
         */
        public function setUserpass($userpass)
        {
            $this->userpass = $userpass;
        }
    
        /**
         * Get userpass
         *
         * @return string
         */
        public function getUserpass()
        {
            return $this->userpass;
        }
    
        /**
         * Set uservalide
         *
         * @param boolean $uservalide
         */
        public function setUservalide($uservalide)
        {
            $this->uservalide = $uservalide;
        }
    
        /**
         * Get uservalide
         *
         * @return boolean
         */
        public function getUservalide()
        {
            return $this->uservalide;
        }
        public function __construct()
        {
            $this->utilroles = new DoctrineCommonCollectionsArrayCollection();
        $this->connexions = new DoctrineCommonCollectionsArrayCollection();
        }
    
        /**
         * Add utilroles
         *
         * @param Google\AFBundle\Entity\Utilroles $utilroles
         */
        public function addUtilroles(GoogleAFBundleEntityUtilroles $utilroles)
        {
            $this->utilroles[] = $utilroles;
        }
    
        /**
         * Get utilroles
         *
         * @return Doctrine\Common\Collections\Collection
         */
        public function getUtilroles()
        {
            return $this->utilroles;
        }
    
        /**
         * Add connexions
         *
         * @param Google\AFBundle\Entity\Connexion $connexions
         */
        public function addConnexions(GoogleAFBundleEntityConnexion $connexions)
        {
            $this->connexions[] = $connexions;
        }
    
        /**
         * Get connexions
         *
         * @return Doctrine\Common\Collections\Collection
         */
        public function getConnexions()
        {
            return $this->connexions;
        }
    
        /**
        * Set username
        *
        * @return Doctrine\Common\Collections\Collection
        */
        public function setUsername($username)
        {
            $this->username = $username;
        }
    
        /**
        * Get username
        *
        * @return string
        */
        public function getUsername()
        {
            return $this->username;
        }
    
        /**
         * Set userlogin
         *
         * @return Doctrine\Common\Collections\Collection
         */
        public function setUserlogin($userlogin)
        {
            $this->userlogin = $userlogin;
        }
    
        /**
        * Get userlogin
        *
        * @return string
        */
        public function getUserlogin()
        {
            return $this->userlogin;
        }
    
    }
    

    如果somone可以提供帮助,我将非常感激。

2 个答案:

答案 0 :(得分:1)

也许我错了,但我认为你在实体文件中拼错了名称空间

namespace GoogleAFBundleEntity;

应该是:

namespace GoogleAFBundle\Entity;

我希望它有所帮助!

答案 1 :(得分:0)

我已经成功了。

实际上,所有数据库字段(mysql)都是生成UPPERcase的。我的$userlogin字段要在数据库中映射到USERLOGIN,如下所示:

/**
* @var string $userlogin
*
* @ORM\Column(name="USERLOGIN", type="string", length=31, nullable=false)
*/
private $userlogin;

我更正了所有字段,并且工作正常。