Bonjour,

Nous sommes actuellement en stage de validation de l'IUT informatique. Le but de notre projet est d'améliorer l'application

actuelle de l'entreprise, programmé à partir du framework Codeigniter. L'application utilise une base de donnée mysql avec

PhpMyAdmin. Il nous a été demandé d'utiliser une nouvelle base de donnée en plus avec mongoDB que l'on doit manipuler

avec doctrineODM.

Nous avons tout d'abord installé composer a partir du site https://getcomposer.org/doc/00*intro.md.

Composer nous a permis d'installer doctrine dans Codeigniter à partir du lien suivant : http://blog.beheist.com/integrating-
codeigniter*and*doctrine*2*orm*with*composer/

Ensuite nous avons installé la librairie mongoDB ODM grâce à la partie SETUP du lien : http://doctrine-
orm.readthedocs.io/projects/doctrine*mongodb*odm/en/latest/reference/introduction.html

N’arrivant pas a créer une connexion à la base de donnée à partir de doctrine, notre maître de stage a supprimé le fichier

bootstrap.php que l'on avait crée comme demandé dans le lien précédant. Nous avons alors remplacer la librairie

doctrine.php par la librairie DoctrineODM.php a partir du lien

https://github.com/openstepmedia/cib...octrineODM.php. Nous avons adapté le code au

mieux pour ne pas utiliser Bonfire.

DoctrineODM.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
 
//phpinfo(); exit();
 
use Doctrine\Common\ClassLoader,
 
Doctrine\ODM\MongoDB\Configuration,
 
Doctrine\Common\Annotations\AnnotationReader,
 
Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver,
 
Doctrine\ODM\MongoDB\DocumentManager,
 
Doctrine\MongoDB\Connection;
 
/**
 
* Doctrine bootstrap library for CodeIgniter
 
*
 
* @author Joseph Wynn <joseph@wildlyinaccurate.com>
 
* @link <a href="http://wildlyinaccurate.com/integrating-doctrine-2-with-codeigniter-2" target="_blank">http://wildlyinaccurate.com/integrat...-codeigniter-2</a>
 
*/
 
class DoctrineODM
 
{
 
public $dm;
 
application/models/Entity/User.php
 
// Set up driver
 
public $em;
 
public function __construct()
 
{
 
require APPPATH.'config/doctrine.php';
 
// With this configuration, your model files need to be in application/models/Entity
 
// e.g. Creating a new Entity\User loads the class from
 
//$models_namespace = 'Documents';
 
foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) {
 
$module = str_replace(APPPATH . 'modules/', '', $m);
 
$loader = new ClassLoader($module, APPPATH . 'modules');
 
$loader->register();
 
}
 
$models = array(APPPATH . 'models');
 
$loader = new ClassLoader('models/', $models);
 
$loader->register();
 
foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) {
 
array_push($models, $m);
 
}
 
//$models_path = APPPATH . 'models';
 
$proxies_dir = APPPATH . 'models/Proxies';
 
$hydrators_dir = APPPATH . 'models/Hydrators';
 
$metadata_paths = array(APPPATH . 'models');
 
$config = new Configuration();
 
'/Documents'));
 
$config->setDefaultDB($db['default']['database']);
 
$config->setProxyDir($proxies_dir);
 
$config->setProxyNamespace('Proxies');
 
$config->setHydratorDir($hydrators_dir);
 
$config->setHydratorNamespace('Hydrators');
 
//$annotationDriver = $config->newDefaultAnnotationDriver(array($models_path .
 
$annotationDriver = $config->newDefaultAnnotationDriver($models);
 
$config->setMetadataDriverImpl($annotationDriver);
 
AnnotationDriver::registerAnnotationClasses();
 
try {
 
$this->dm = DocumentManager::create($connection, $config);
 
} catch (Exception $ex) {
 
var_dump($e->getMessage());
 
}
 
//$this->generate_classes();
 
}
 
$connection = new Connection($db['default']['server'] );
 
DoctrineODM.php utilise le fichier de config de doctrine afin de se connecter a la bonne base de donnée :
 
config/doctrine.php :
 
$db['default']['server'] = 'mongodb://localhost:8081';
 
$db['default']['username'] = 'admin';
 
$db['default']['password'] = '****';
 
$db['default']['database'] = 'pillar';
Nous avons créer un controleur test.php affin de tester la connection :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Test extends CI_Controller {
 
/**
 
* Index Page for this controller.
 
*
 
* Maps to the following URL
 
* <a href="http://example.com/index.php/welcome" target="_blank">http://example.com/index.php/welcome</a>
 
* - or -
 
* <a href="http://example.com/index.php/welcome/index" target="_blank">http://example.com/index.php/welcome/index</a>
 
* - or -
 
* Since this controller is set as the default controller in
 
* config/routes.php, it's displayed at <a href="http://example.com/" target="_blank">http://example.com/</a>
 
*
 
* So any other public methods not prefixed with an underscore will
 
* map to /index.php/welcome/<method_name>
 
* @see <a href="http://codeigniter.com/user_guide/general/urls.html" target="_blank">http://codeigniter.com/user_guide/general/urls.html</a>
 
*/
 
public function iparla()
 
{
 
$connection = new \Doctrine\MongoDB\Connection();
 
d($connection); //fonction de débogage de kint
 
$doc = new DoctrineODM();
 
$connect = $doc->dm->getConnection();
 
$dm=$doc->dm->getRepository('User');
 
}
 
}
 
/* End of file test.php */
 
/* Location: ./application/controllers/test.php */
 
?>
Nous n'avons pas reussi à se connecter a la base de donnée et à générer les entités de la base de donnée.

Nous avons tout de même créer la classe models/Entity/User.php à la main afin de vérifier le bon fonctionnement de

doctrine.

Les erreur suivantes ont été générées :
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information * headers already sent by (output started at /home/www/fast-
mage/admin/applicationhiddenci/libraries/Kint/Kint.php:276)

Filename: core/Common.php

Line Number: 573
An uncaught Exception was encountered

Type: Doctrine\Common\Persistence\Mapping\MappingException

Message: Class 'User' does not exist

Filename: /home/www/fast-
mage/admin/applicationhiddenci/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php

Line Number: 96
Nous sommes actuellement bloqué, et ne savons pas où chercher,les données concernant la BD sont biens reçus par le

DocumentManager mais la connexion à MongoClient ne se fait pas.

Merci d'avance pour avoir lu ce post et pour votre possible aide.