1 | <?php |
---|
2 | |
---|
3 | class Doctrine |
---|
4 | { |
---|
5 | // the Doctrine entity manager |
---|
6 | public $em = null; |
---|
7 | |
---|
8 | public function __construct() |
---|
9 | { |
---|
10 | // include our CodeIgniter application's database configuration |
---|
11 | require_once APPPATH.'config/database.php'; |
---|
12 | |
---|
13 | // include Doctrine's fancy ClassLoader class |
---|
14 | require_once APPPATH.'libraries/Doctrine/Common/ClassLoader.php'; |
---|
15 | |
---|
16 | // load the Doctrine classes |
---|
17 | $doctrineClassLoader = new \Doctrine\Common\ClassLoader('Doctrine', APPPATH.'libraries'); |
---|
18 | $doctrineClassLoader->register(); |
---|
19 | |
---|
20 | // load Symfony2 helpers |
---|
21 | // Don't be alarmed, this is necessary for YAML mapping files |
---|
22 | $symfonyClassLoader = new \Doctrine\Common\ClassLoader('Symfony', APPPATH.'libraries/Doctrine'); |
---|
23 | $symfonyClassLoader->register(); |
---|
24 | |
---|
25 | // load the entities |
---|
26 | $entityClassLoader = new \Doctrine\Common\ClassLoader('Entities', APPPATH.'models'); |
---|
27 | $entityClassLoader->register(); |
---|
28 | |
---|
29 | // load the proxy entities |
---|
30 | $proxyClassLoader = new \Doctrine\Common\ClassLoader('Proxies', APPPATH.'models'); |
---|
31 | $proxyClassLoader->register(); |
---|
32 | |
---|
33 | // set up the configuration |
---|
34 | $config = new \Doctrine\ORM\Configuration; |
---|
35 | |
---|
36 | if(ENVIRONMENT == 'development') |
---|
37 | // set up simple array caching for development mode |
---|
38 | $cache = new \Doctrine\Common\Cache\ArrayCache; |
---|
39 | else |
---|
40 | // set up caching with APC for production mode |
---|
41 | $cache = new \Doctrine\Common\Cache\ApcCache; |
---|
42 | $config->setMetadataCacheImpl($cache); |
---|
43 | $config->setQueryCacheImpl($cache); |
---|
44 | |
---|
45 | // set up proxy configuration |
---|
46 | $config->setProxyDir(APPPATH.'models/Proxies'); |
---|
47 | $config->setProxyNamespace('Proxies'); |
---|
48 | |
---|
49 | // auto-generate proxy classes if we are in development mode |
---|
50 | $config->setAutoGenerateProxyClasses(ENVIRONMENT == 'development'); |
---|
51 | |
---|
52 | // set up annotation driver |
---|
53 | $yamlDriver = new \Doctrine\ORM\Mapping\Driver\YamlDriver(APPPATH.'models/Mappings'); |
---|
54 | $config->setMetadataDriverImpl($yamlDriver); |
---|
55 | |
---|
56 | // Database connection information |
---|
57 | $connectionOptions = array( |
---|
58 | 'driver' => 'pdo_mysql', |
---|
59 | 'user' => 'root', |
---|
60 | 'password' => 'Quyenhue@123', |
---|
61 | 'host' => 'localhost', |
---|
62 | 'dbname' => 'violet-viettel', |
---|
63 | 'charset' => 'utf8', |
---|
64 | 'driverOptions' => array( |
---|
65 | 1002=>'SET NAMES utf8' |
---|
66 | ) |
---|
67 | ); |
---|
68 | |
---|
69 | |
---|
70 | // create the EntityManager |
---|
71 | $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config); |
---|
72 | |
---|
73 | // store it as a member, for use in our CodeIgniter controllers. |
---|
74 | $this->em = $em; |
---|
75 | } |
---|
76 | } |
---|