0

EDIT : New issue

I have got some new stuff :

I am pretty sure it is the xml files that are messing all up.

Here is how I proceeded :

  1. I made my own database scheme
  2. I created the database (sql script)
  3. I reverse-engineered the database
  4. I fixed the associations between tables.

In my XML conf repository : src/Creasixtine/AFBundle/Resources/config/doctrine/metadata/orm

I have my all entities :

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

And here is, for example, the xml file of Utilisateur :

<?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>

And with that, I get :

Notice: Undefined index: id in /home/adrien/dev/air-france_alphanum/vendor/doctrine/lib/Doctrine/ORM/UnitOfWork.php line 1969

Old post

I have (long ago) imported a database schema.

I have a Utilisateur Entity/Class. I successly create new recordings in my Utilisateur table by doing :

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();

    }

Now what won't work : I would like to get existing users in database :

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

And I get an exception :

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

Here is the Utilisateur class :

<?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;
    }

}

If somone can help, I would greatly appreciate.

Creasixtine
  • 740
  • 3
  • 11
  • 33

2 Answers2

1

Maybe I'm wrong, but I think you mispelled the namespace in your entity file.

namespace GoogleAFBundleEntity;

Should be:

namespace GoogleAFBundle\Entity;

I hope it helps!

alghimo
  • 2,899
  • 18
  • 11
0

I've managed it.

In fact, all database fields (mysql) were generated UPPERcase. My $userlogin field was to be mapped in database to USERLOGIN, as follows :

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

I corrected all fields, and it works properly.

Creasixtine
  • 740
  • 3
  • 11
  • 33