Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > ORM > Doctrine
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 13/06/2011, 16h31   #1
Invité de passage
 
Homme vincent Delvallée
Inscription : novembre 2004
Messages : 6
Détails du profil
Informations personnelles :
Nom : Homme vincent Delvallée

Informations forums :
Inscription : novembre 2004
Messages : 6
Points : 2
Points : 2
Par défaut Warning: class_parents() [function.class-parents]

Je teste pour la première Doctrine version 2.0.5.
J'ai récupérer les sources via le download et installé dans RACINE/LibrairiePhp/doctrine-orm/. RACINE étant le chemin à partir de la racine du serveur.

J'ai crée un fichier de test à la racine de mon site (au même niveau de LibrairiePhp)
test.php:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 
 
<?php
 
require_once(RACINE.'/LibrairiePhp/doctrine-orm/Doctrine/Common/ClassLoader.php');
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', RACINE.'/LibrairiePhp/doctrine-orm/');
$classLoader->register(); // register on SPL autoload stack
 
use Doctrine\ORM\EntityManager,
    Doctrine\ORM\Configuration;
 
// ...
//cette variable permet de switcher entre l'environnement de dev et de prod
$applicationMode = 'developpement';
if ($applicationMode == DOCTRINECONFIGURATION) {
    $cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
    $cache = new \Doctrine\Common\Cache\ApcCache;
}
 
$config = new Configuration;
$config->setMetadataCacheImpl($cache);
 
$driverImpl = $config->newDefaultAnnotationDriver(RACINE.'/Model/Entities'); 
$config->setMetadataDriverImpl($driverImpl); 
 
$config->setQueryCacheImpl($cache);
 
$config->setProxyDir(RACINE.'/Model/Proxies');
$config->setProxyNamespace('\Model\Proxies');
$config->setAutoGenerateProxyClasses(false);
 
/*
$config->setSQLLogger($logger);
$config->getSQLLogger();
*/
 
$connectionOptions = array(
    'dbname' => DATABASE,
    'user' => SQLUSER,
    'password' => SQLUSERPWD,
    'host' => SQLSERVER,
    'driver' => 'pdo_mysql',
);
 
$em = EntityManager::create($connectionOptions, $config);
 
 
		// custom datatypes (not mapped for reverse engineering)
		$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string');
		$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
		$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('blob', 'string');
 
		// fetch metadata
		$driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver(
			$em->getConnection()->getSchemaManager()
		);
		$em->getConfiguration()->setMetadataDriverImpl($driver);
		$cmf = new \Doctrine\ORM\Tools\DisconnectedClassMetadataFactory($em);
		$cmf->setEntityManager($em); 
 
		$metadata = $cmf->getAllMetadata(); 
	/*	
		$generator = new \Doctrine\ORM\Tools\EntityGenerator();
		$generator->setGenerateAnnotations(true);
		$generator->setUpdateEntityIfExists(false);
		$generator->setGenerateStubMethods(true);
		$generator->setGenerateAnnotations(true);
		$generator->generate($metadata, RACINE.'/Model/Entities');
                echo 'Done';
*/
 
		$classLoader = new \Doctrine\Common\ClassLoader('Model', RACINE.'/Model/Entities/');
		$classLoader->register(); // register on SPL autoload stack*/
 
 
 
 
 
 
$users = $em->find('Utilisateurs', 1);
 
 
//$users = $em->getRepository('Utilisateurs')->findBy(array('idUtilisateurs' => 1));
 
 
		print_r($users);
 
 
 
 
 
?>
Mes classes se crées bien dans /Model/Entities/
par contre je suis surpris de ne pas avoir de namespace Model\Entities en haut de ces classes, mais c'est peut être normal.

En revanche dès que je tente une requête, j'ai l'erreur suivante:

Code :
1
2
3
4
5
6
7
8
9
 
 
Warning: class_parents() [function.class-parents]: Class Utilisateurs does not exist and could not be loaded in C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
 
Warning: array_reverse() expects parameter 1 to be array, boolean given in C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
 
Warning: Invalid argument supplied for foreach() in C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php on line 222
 
Fatal error: Uncaught exception 'ReflectionException' with message 'Class Utilisateurs does not exist' in C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadata.php:67 Stack trace: #0 C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadata.php(67): ReflectionClass->__construct('Utilisateurs') #1 C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php(351): Doctrine\ORM\Mapping\ClassMetadata->__construct('Utilisateurs') #2 C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php(260): Doctrine\ORM\Mapping\ClassMetadataFactory->newClassMetadataInstance('Utilisateurs') #3 C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadataFactory.php(169): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('Utilisateurs') #4 C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\EntityManager.php(251): Doctrine\ORM\Mapping\ClassMet in C:\workspacePhp\frameworkPhp\LibrairiePhp\doctrine-orm\Doctrine\ORM\Mapping\ClassMetadata.php on line 67
Quelqu'un aurait il une idée l'origine du l'erreur?
Merci à l'avance pour votre aide.
vincent.delvallee est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 16h02   #2
Invité de passage
 
Homme vincent Delvallée
Inscription : novembre 2004
Messages : 6
Détails du profil
Informations personnelles :
Nom : Homme vincent Delvallée

Informations forums :
Inscription : novembre 2004
Messages : 6
Points : 2
Points : 2
Par défaut problème localisé

Le problème vient de l'autoloader
si je fais un require avant
Code :
require_once(RACINE."/Model/Entities/Utilisateurs.php");
Code :
$users = $em->find('Utilisateurs', 1);
fonctionne parfaitement.

Il y donc une erreur sur l'autoloader mais que je n'ai pas encore localisé.

Merci d'avance pour vos retour
vincent.delvallee est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/06/2011, 16h56   #3
Invité de passage
 
Homme vincent Delvallée
Inscription : novembre 2004
Messages : 6
Détails du profil
Informations personnelles :
Nom : Homme vincent Delvallée

Informations forums :
Inscription : novembre 2004
Messages : 6
Points : 2
Points : 2
Par défaut problème localisé et résolu

J'ai supprimé
Code :
1
2
$classLoader = new \Doctrine\Common\ClassLoader('Model', RACINE.'/Model/Entities/');
$classLoader->register(); // register on SPL autoload stack*/
et utilisé mon propre autoloader

maintenant cela fonctionne parfaitement

Merci
vincent.delvallee est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h00.


 
 
 
 
Partenaires

Hébergement Web