Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // bootstrap.php
- define('APPLICATION_ENV', 'development');
- // Setup Autoloader (1)
- // See :doc:`Configuration <../reference/configuration>` for up to date autoloading details.
- require_once '../../lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php';
- $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\ORM', realpath(__DIR__ . '/../../lib'));
- $classLoader->register();
- $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\DBAL', realpath(__DIR__ . '/../../lib/vendor/doctrine-dbal/lib'));
- $classLoader->register();
- $classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Common', realpath(__DIR__ . '/../../lib/vendor/doctrine-common/lib'));
- $classLoader->register();
- $classLoader = new \Doctrine\Common\ClassLoader('Symfony', realpath(__DIR__ . '/../../lib/vendor'));
- $classLoader->register();
- $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
- $classLoader->register();
- $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
- $classLoader->register();
- $config = new Doctrine\ORM\Configuration(); // (2)
- // Proxy Configuration (3)
- $config->setProxyDir(__DIR__.'/Proxies');
- $config->setProxyNamespace('Proxies');
- $config->setAutoGenerateProxyClasses((APPLICATION_ENV == 'development'));
- // Mapping Configuration (4)
- $driverImpl = $config->newDefaultAnnotationDriver(__DIR__.'/Entities');
- $config->setMetadataDriverImpl($driverImpl);
- // Caching Configuration (5)
- if (APPLICATION_ENV == 'development') {
- $cache = new \Doctrine\Common\Cache\ArrayCache();
- } else {
- $cache = new \Doctrine\Common\Cache\ApcCache();
- }
- $config->setMetadataCacheImpl($cache);
- $config->setQueryCacheImpl($cache);
- // database configuration parameters (6)
- $conn = array(
- 'driver' => 'pdo_mysql',
- 'host' => 'host',
- 'dbname' => 'tbl',
- 'user' => 'user',
- 'password' => 'pw'
- );
- // obtaining the entity manager (7)
- $em = \Doctrine\ORM\EntityManager::create($conn, $config);
- ?>
- <?php // test.php
- require_once 'bootstrap.php';
- $widgets = $em->find('Widgets', 1);
- var_dump($widgets);
- ?>
- <?php // Entities/Widgets.php
- /**
- * Widgets
- *
- * @Table(name="widgets")
- * @Entity
- */
- class Widgets
- {
- /**
- * @var integer $id
- *
- * @Column(name="id", type="integer", nullable=false)
- * @Id
- * @GeneratedValue
- */
- private $id;
- /**
- * @var string $sourceUrl
- *
- * @Column(name="source_url", type="string", length=2048, nullable=false)
- */
- private $sourceUrl;
- /**
- * @var boolean $isextern
- *
- * @Column(name="isextern", type="boolean", nullable=false)
- */
- private $isextern;
- //...
- ?>
- sandbox$ l Entities/
- drwxr-sr-x 2 user group 0 2011-02-09 13:01 ./
- drwxr-sr-x 6 user group 0 2011-02-09 14:40 ../
- -rw-rw-r-- 1 user group 1,5K 2011-02-09 13:42 Widgets.php
- sandbox$ php test.php
- 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
- PHP Stack trace:
- PHP 1. {main}() doctrine2-orm/tools/sandbox/test.php:0
- PHP 2. Doctrine\ORM\EntityManager->find() doctrine2-orm/tools/sandbox/test.php:4
- PHP 3. Doctrine\ORM\EntityManager->getRepository() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:340
- PHP 4. Doctrine\ORM\EntityManager->getClassMetadata() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:563
- PHP 5. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() doctrine2-orm/lib/Doctrine/ORM/EntityManager.php:247
- PHP 6. Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:169
- PHP 7. Doctrine\ORM\Mapping\ClassMetadataFactory->getParentClasses() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:245
- PHP 8. class_parents() doctrine2-orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:222
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement