I have downloaded doctrine 2.2 orm. I have gone through its installation guide but i cant properly understand its documentation. Can someone guide me through the setup process of doctrine. I have previously been working with Hibernate ORM framework in java. They have excellent documentation which are easy to understand for beginners. I dont find the documentation of doctrine to be of that level. Can somebody provide some sample projects on doctrine to begin with?
2条回答 默认 最新
- duanjiao2978 2012-06-26 01:03关注
There are several ways on how to install doctrine to your website project. I will show you an easy alternative:
-
Download doctrine package and uncompressed inin your server. Now your directory looks like this:
localhost/Doctrine
localhost/Doctrine/Common
localhost/Doctrine/ORM
localhost/Doctrine/DBAL -
You need to create two additionals folder in order to store your models (persistence entities), and proxies:
localhost/models
localhost/proxies -
Create a class that will in charge of create the EntityManager object and the connection to database. Lets create the magic class named Doctrine:
localhost/doctrine.php
Setting the properties:
<?php use Doctrine\Common\ClassLoader, Doctrine\ORM\Configuration, Doctrine\ORM\EntityManager, Doctrine\Common\Cache\ArrayCache, Doctrine\DBAL\Logging\EchoSQLLogger; class Doctrine{ public $em = null; public function __construct() { require_once 'Doctrine/Common/ClassLoader.php'; $doctrineClassLoader = new ClassLoader('Doctrine', '/'); $doctrineClassLoader->register(); $entitiesClassLoader = new ClassLoader('models', '/models/'); $entitiesClassLoader->register(); $proxiesClassLoader = new ClassLoader('Proxies', '/proxies/'); $proxiesClassLoader->register(); // Set up caches $config = new Configuration; $cache = new ArrayCache; $config->setMetadataCacheImpl($cache); $driverImpl = $config->newDefaultAnnotationDriver(array('/models/Entities')); $config->setMetadataDriverImpl($driverImpl); $config->setQueryCacheImpl($cache); $config->setQueryCacheImpl($cache); // Proxy configuration $config->setProxyDir('/proxies'); $config->setProxyNamespace('Proxies'); // Set up logger $logger = new EchoSQLLogger; //$config->setSQLLogger($logger); $config->setAutoGenerateProxyClasses( TRUE ); // Database connection information $connectionOptions = array( 'driver' => 'pdo_mysql', 'user' => 'USER', 'password' => 'PASS', 'host' => 'HOST', 'dbname' => 'DB_NAME' ); // Create EntityManager $this->em = EntityManager::create($connectionOptions, $config); } }
Now your able to use the entityManager in you website once you have included it.
$doctrine = new Doctrine(); $user = new models\User; $doctrine->em->persist($user); $doctrine->em->flush();
Al least this post can help you to take the idea on how to install and use doctrine
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 -
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog