Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php // bootstrap.php
  2. define('APPLICATION_ENV', 'development');
  3.  
  4. // Setup Autoloader (1)
  5. // See :doc:`Configuration <../reference/configuration>` for up to date autoloading details.
  6. require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
  7. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
  8. $classLoader->register();
  9. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
  10. $classLoader->register();
  11. $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
  12. $classLoader->register();
  13. $classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
  14. $classLoader->register();
  15. $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
  16. $classLoader->register();
  17. $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
  18. $classLoader->register();
  19.  
  20. $config = new Doctrine\ORM\Configuration(); // (2)
  21.  
  22. // Proxy Configuration (3)
  23. $config->setProxyDir(__DIR__.'/Proxies');
  24. $config->setProxyNamespace('Proxies');
  25. $config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development'));
  26.  
  27. // Mapping Configuration (4)
  28. $driverImpl = $config->newDefaultAnnotationDriver(__DIR__.'/Entities');
  29. $config->setMetadataDriverImpl($driverImpl);
  30.  
  31. // Caching Configuration (5)
  32. if (APPLICATION_ENV == 'development') {
  33.     $cache = new \Doctrine\Common\Cache\ArrayCache();
  34. } else {
  35.     $cache = new \Doctrine\Common\Cache\ApcCache();
  36. }
  37. $config->setMetadataCacheImpl($cache);
  38. $config->setQueryCacheImpl($cache);
  39.  
  40. // database configuration parameters (6)
  41. $conn = array(
  42.     'driver' => 'pdo_mysql',
  43.     'host' => 'host',
  44.     'dbname' => 'tbl',
  45.     'user' => 'user',
  46.     'password' => 'pw'
  47. );
  48.  
  49. // obtaining the entity manager (7)
  50. $em = \Doctrine\ORM\EntityManager::create($conn, $config);
  51. ?>
  52.  
  53.  
  54. <?php // test.php
  55. require_once 'bootstrap.php';
  56.  
  57. $widgets = $em->find('Widgets', 1);
  58.  
  59. var_dump($widgets);
  60. ?>
  61.  
  62.  
  63. <?php // Entities/Widgets.php
  64.  
  65. /**
  66.  * Widgets
  67.  *
  68.  * @Table(name="widgets")
  69.  * @Entity
  70.  */
  71. class Widgets
  72. {
  73.    
  74.     /**
  75.      * @var integer $id
  76.      *
  77.      * @Column(name="id", type="integer", nullable=false)
  78.      * @Id
  79.      * @GeneratedValue
  80.      */
  81.     private $id;
  82.  
  83.     /**
  84.      * @var string $sourceUrl
  85.      *
  86.      * @Column(name="source_url", type="string", length=2048, nullable=false)
  87.      */
  88.     private $sourceUrl;
  89.  
  90.     /**
  91.      * @var boolean $isextern
  92.      *
  93.      * @Column(name="isextern", type="boolean", nullable=false)
  94.      */
  95.     private $isextern;
  96. //...
  97. ?>
  98.  
  99. sandbox$ l Entities/
  100. drwxr-sr-x 2 user group    0 2011-02-09 13:01 ./
  101. drwxr-sr-x 6 user group    0 2011-02-09 14:40 ../
  102. -rw-rw-r-- 1 user group 1,5K 2011-02-09 13:42 Widgets.php
  103.  
  104.  
  105.  
  106.  
  107. sandbox$ php test.php
  108. PHP Warning:  class_parents(): Class Widgets does not exist and could not be loaded in doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 222
  109. PHP Stack trace:
  110. PHP   1. {main}() doctrine2-orm/tools/sandbox/test.php:0
  111. PHP   2. Doctrine\ORM\EntityManager->find() doctrine2-orm/tools/sandbox/test.php:4
  112. PHP   3. Doctrine\ORM\EntityManager->getRepository() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:340
  113. PHP   4. Doctrine\ORM\EntityManager->getClassMetadata() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:563
  114. PHP   5. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:247
  115. PHP   6. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:169
  116. PHP   7. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:245
  117. PHP   8. class_parents() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:222
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement