I just started to use Doctrine2 and I have an error when I want to persist an entity. Here is my error: 'Class "Myapp\app\entity\user" is not a valid entity or mapped super class.'
eAccelerator is not installed on my computer.
My app (I don't use Symfony) structure is like that:
- MyApp
- app
- entity
- core
- external
- Doctrine
- external
- app
And I initialize Doctrine with:
$classLoader = new ClassLoader('Doctrine', CORE_PATH . 'external');
$classLoader->register();
$cache = new \Doctrine\Common\Cache\ArrayCache();
$doctrineConfig = new \Doctrine\ORM\Configuration();
$doctrineConfig->setMetadataCacheImpl($cache);
$doctrineConfig->setQueryCacheImpl($cache);
$driverImpl = $doctrineConfig->newDefaultAnnotationDriver(array(APP_PATH . 'entity'));
$doctrineConfig->setMetadataDriverImpl($driverImpl);
$doctrineConfig->setAutoGenerateProxyClasses(false);
$connectionOptions = array(
'driver' => $database['driver'],
'dbname' => $database['dbname'],
'user' => $database['username'],
'password' => $database['password']
);
$this->em = EntityManager::create($connectionOptions, $doctrineConfig);
What is wrong with these lines ?
Also as I autoload my classes with an autoloader, is it necessary to use the Doctrine class loader ? If yes, are these lines correct ?
$classLoader = new ClassLoader('myApp\app\entity', APP_PATH . 'entity');
$classLoader->register();
$classLoader = new ClassLoader('myApp\core\entity', CORE_PATH . 'entity');
$classLoader->register();
Edit: I forgot to add an entity class
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class user
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="username", type="string", length=255)
*/
protected $username;
/**
* @ORM\Column(name="nicename", type="string", length=255)
*/
protected $nicename;
/**
* @ORM\Column(name="email", type="string", length=255)
*/
protected $email;
/**
* @ORM\Column(name="password", type="string", length=255)
*/
protected $password;
//getters
//setters