dtlhy0771 2011-07-07 19:17
浏览 41

PHP配置的Doctrine

Hi, everyone!

I'm building a PHP site and I decided to go with Doctrine as DBAL and ORM. I'm a bit rusty on my PHP skills, so please help me understand one thing.

The way to configure Doctrine, as specified in their docs is to execute code like this:

if ($applicationMode == "development") {
    $cache = new \Doctrine\Common\Cache\ArrayCache;
} else {
    $cache = new \Doctrine\Common\Cache\ApcCache;
}

$config = new Configuration;
$config->setMetadataCacheImpl($cache);
$driverImpl = $config->newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
$config->setMetadataDriverImpl($driverImpl);
$config->setQueryCacheImpl($cache);
$config->setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
$config->setProxyNamespace('MyProject\Proxies');

if ($applicationMode == "development") {
    $config->setAutoGenerateProxyClasses(true);
} else {
    $config->setAutoGenerateProxyClasses(false);
}

$connectionOptions = array(
    'driver' => 'pdo_sqlite',
    'path' => 'database.sqlite'
);

What I'm puzzled about is how should you execute this code. Is it something you put in a config.php file and include in each of your pages, basically executing this each time a page is processed? Or am I supposed to do this configuration once?

On a related note - please help me understand how setting cache to ArrayCache instead of APC cache helps me during development?

Thanks!

  • 写回答

1条回答 默认 最新

  • dsy19811981 2011-07-07 19:37
    关注

    doctrine is a pretty hard choice if your PHP skills are rusty... Anyway...

    You can create the connection and eventmanger once in a bootstrap file. Then you can pass the eventmanager instance to your class constructors or make it availably through a static registry (dirty dirty dirty) or ...

    This is a good starting point (for orm 2.0):

    http://www.doctrine-project.org/docs/orm/2.0/en/tutorials/getting-started-xml-edition.html

    The only reason for using ArrayCache in dev mode I can think of is, that you do not have to configure APC at that point and can focus on your coding. In production mode APC gives you the extra boost and is highly recommended.

    Regards Flo

    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单