Posted By

farstar78 on 07/19/11


Tagged

cli codeigniter doctrine2


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


cli-config.php - doctrine2 + codeigniter2


 / Published in: PHP
 

  1. <?php
  2. use Doctrine\Common\ClassLoader,
  3. Doctrine\ORM\Configuration,
  4. Doctrine\ORM\EntityManager,
  5. Doctrine\Common\Cache\ArrayCache,
  6. Doctrine\DBAL\Logging\EchoSqlLogger;
  7.  
  8. define('BASEPATH', __DIR__ . '/../system/');
  9.  
  10. require_once __DIR__ . '/config/database.php';
  11. require_once BASEPATH . 'core/Model.php';
  12. require_once __DIR__ . '/libraries/Doctrine/Common/ClassLoader.php';
  13.  
  14. $doctrineClassLoader = new ClassLoader('Doctrine', __DIR__.'/libraries');
  15. $doctrineClassLoader->register();
  16. $entitiesClassLoader = new ClassLoader('models', __DIR__);
  17. $entitiesClassLoader->register();
  18. $proxiesClassLoader = new ClassLoader('Proxies', __DIR__.'/models/proxies');
  19. $proxiesClassLoader->register();
  20. $config = new \Doctrine\ORM\Configuration();
  21. $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
  22. $config->setProxyDir(__DIR__ . '/Proxies');
  23. $config->setProxyNamespace('Proxies');
  24.  
  25. $cache = new ArrayCache;
  26. // Set up driver
  27. $Doctrine_AnnotationReader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
  28. $Doctrine_AnnotationReader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
  29. $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($Doctrine_AnnotationReader, realpath('../models'));
  30. $config->setMetadataDriverImpl($driver);
  31.  
  32. // Database connection information
  33. $connectionOptions = array(
  34. 'driver' => 'pdo_mysql',
  35. 'user' => $db['default']['username'],
  36. 'password' => $db['default']['password'],
  37. 'host' => $db['default']['hostname'],
  38. 'dbname' => $db['default']['database']
  39. );
  40.  
  41. $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
  42.  
  43. $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
  44. 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
  45. 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
  46. ));

Report this snippet  

You need to login to post a comment.