仕事でZendFramework1.*を使用することになったので、ORMにDoctrine2.3.*を使用してみました。
下記の記事は、ある程度ZendFrameworkを触ったことがある方が対象になると思います。
構築環境
composerを使ってやりたかったのですが、うまくいかなかったので、結局手動で、Fileをダウンロードして設定しました。
- Ubuntu 12.04
- PHP 5.3.10
- memcache 2.2.7
- ZendFramework 1.12.1
- Doctrine 2.3.0
設定に入る前に
KDF Memoさんの記事を参考に導入しました。
おそらく、KDF Memoさんものより、Versionが上がっているので、File構成がだいぶ変わってきているので、地味に設定に時間がかかりました。
設定
まず、必要なものをダウンロード
Doctrine ORMよりLatestをダウンロードして、./library/vendor/に入れる
zendframework1-doctrine2より、Bisnaをダウンロードして、./libraryに入れるbinフォルダをコピーして、./に移動
cacheの設定などは、KDF Memoさんの記事に詳しく書いてありますのでそちらを参照してください。
application.iniを書き換える
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
[production] ; -------------------------- ; PHP Specific Configuration ; -------------------------- phpSettings.display_startup_errors = 0 phpSettings.display_errors = 0 includePaths.library = APPLICATION_PATH "/../library" ; ---------------------------------------- ; Zend Framework Application Configuration ; ---------------------------------------- bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap" pluginPaths.BisnaApplicationResource = "Bisna/Application/Resource" autoloaderNamespaces[] = Bisna autoloaderNamespaces[] = ApplicationEntity appnamespace = "Application" ; ------------------------------ ; Front Controller Configuration ; ------------------------------ resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.params.displayExceptions = 0 ; ------------------------------------------------------------------------------ ; Doctrine Class Loader Configuration ; ------------------------------------------------------------------------------ resources.doctrine.classLoader.loaderClass = "DoctrineCommonClassLoader" resources.doctrine.classLoader.loaderFile = APPLICATION_PATH "/../library/vendor/Doctrine/Doctrine/Common/ClassLoader.php" resources.doctrine.classLoader.loaders.doctrine_common.namespace = "DoctrineCommon" resources.doctrine.classLoader.loaders.doctrine_common.includePath = APPLICATION_PATH "/../library/vendor/Doctrine" resources.doctrine.classLoader.loaders.doctrine_dbal.namespace = "DoctrineDBAL" resources.doctrine.classLoader.loaders.doctrine_dbal.includePath = APPLICATION_PATH "/../library/vendor/Doctrine" resources.doctrine.classLoader.loaders.doctrine_orm.namespace = "DoctrineORM" resources.doctrine.classLoader.loaders.doctrine_orm.includePath = APPLICATION_PATH "/../library/vendor/Doctrine" resources.doctrine.classLoader.loaders.symfony_console.namespace = "SymfonyComponentConsole" resources.doctrine.classLoader.loaders.symfony_console.includePath = APPLICATION_PATH "/../library/vendor/Doctrine/Doctrine" resources.doctrine.classLoader.loaders.symfony_yaml.namespace = "SymfonyComponentYaml" resources.doctrine.classLoader.loaders.symfony_yaml.includePath = APPLICATION_PATH "/../library/vendor/Doctrine/Doctrine" ; ------------------------------------------------------------------------------ ; Doctrine Cache Configuration ; ------------------------------------------------------------------------------ ; Points to default cache instance to be used. Optional is only one cache is defined resources.doctrine.cache.defaultCacheInstance = default ; Cache Instance configuration for "default" cache ;resources.doctrine.cache.instances.default.id = default resources.doctrine.cache.instances.default.adapterClass = "DoctrineCommonCacheMemcacheCache" resources.doctrine.cache.instances.default.namespace = "Application_" resources.doctrine.cache.instances.default.options.servers.0.host = localhost resources.doctrine.cache.instances.default.options.servers.0.port = 11211 ;resources.doctrine.cache.instances.default.options.servers.0.persistent = true ;resources.doctrine.cache.instances.default.options.servers.0.weight = 1 ;resources.doctrine.cache.instances.default.options.servers.0.timeout = 1 ;resources.doctrine.cache.instances.default.options.servers.0.retryInterval = 15 ;resources.doctrine.cache.instances.default.options.servers.0.status = true ; ------------------------------------------------------------------------------ ; Doctrine DBAL Configuration ; ------------------------------------------------------------------------------ ; Points to default connection to be used. Optional if only one connection is defined resources.doctrine.dbal.defaultConnection = default ; DBAL Connection configuration for "default" connection ;resources.doctrine.dbal.connections.default.id = default ;resources.doctrine.dbal.connections.default.eventManagerClass = "DoctrineCommonEventManager" ;resources.doctrine.dbal.connections.default.eventSubscribers[] = "DoctrineExtensionsSluggableSluggableSubscriber" ;resources.doctrine.dbal.connections.default.configurationClass = "DoctrineDBALConfiguration" ;resources.doctrine.dbal.connections.default.sqlLoggerClass = "DoctrineDBALLoggingEchoSQLLogger" ;resources.doctrine.dbal.connections.default.types.my_type = "ApplicationDBALTypeMyType" ; Database configuration ;resources.doctrine.dbal.connections.default.parameters.wrapperClass = "" resources.doctrine.dbal.connections.default.parameters.driver = "pdo_mysql" resources.doctrine.dbal.connections.default.parameters.dbname = "databasename" resources.doctrine.dbal.connections.default.parameters.host = "localhost" resources.doctrine.dbal.connections.default.parameters.port = 3306 resources.doctrine.dbal.connections.default.parameters.user = "root" resources.doctrine.dbal.connections.default.parameters.password = "password" ;resources.doctrine.dbal.connections.default.parameters.driverOptions.ATTR_USE_BUFFERED_QUERIES = true ; ------------------------------------------------------------------------------ ; Doctrine ORM Configuration ; ------------------------------------------------------------------------------ ; Points to default EntityManager to be used. Optional if only one EntityManager is defined resources.doctrine.orm.defaultEntityManager = default ; EntityManager configuration for "default" manager ;resources.doctrine.orm.entityManagers.default.id = default ;resources.doctrine.orm.entityManagers.default.entityManagerClass = "DoctrineORMEntityManager" ;resources.doctrine.orm.entityManagers.default.configurationClass = "DoctrineORMConfiguration" ;resources.doctrine.orm.entityManagers.default.defaultRepositoryClass = "DoctrineORMEntityRepository" ;resources.doctrine.orm.entityManagers.default.entityNamespaces.app = "ApplicationEntity" ;resources.doctrine.orm.entityManagers.default.connection = default ;resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true ;resources.doctrine.orm.entityManagers.default.proxy.namespace = "ApplicationEntityProxy" ;resources.doctrine.orm.entityManagers.default.proxy.dir = APPLICATION_PATH "/../library/Application/Entity/Proxy" ;resources.doctrine.orm.entityManagers.default.metadataCache = default ;resources.doctrine.orm.entityManagers.default.queryCache = default ;resources.doctrine.orm.entityManagers.default.resultCache = default ;resources.doctrine.orm.entityManagers.default.DQLFunctions.numeric.PI = "DoctrineExtensionsORMQueryFunctionsNumericPiFunction" resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationFiles[] = APPLICATION_PATH "/../library/vendor/Doctrine/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php" ;resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationNamespaces.0.namespace = "Gedmo" ;resources.doctrine.orm.entityManagers.default.metadataDrivers.annotationRegistry.annotationNamespaces.0.includePath = APPLICATION_PATH "/../library/vendor" resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.adapterClass = "DoctrineORMMappingDriverAnnotationDriver" resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingNamespace = "ApplicationEntity" resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.mappingDirs[] = APPLICATION_PATH "/../library/Application/Entity" resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderClass = "DoctrineCommonAnnotationsAnnotationReader" resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderCache = default ;resources.doctrine.orm.entityManagers.default.metadataDrivers.drivers.0.annotationReaderNamespaces.App = "ApplicationDoctrineExtensionsORMMapping" ; DocumentManager configuration for "default" manager resources.doctrine.odm.documentManagers.default.documentManagerClass = "DoctrineODMMongoDBDocumentManager" resources.doctrine.odm.documentManagers.default.connectionString = "mongodb://localhost" resources.doctrine.odm.documentManagers.default.type = "MongoDB" resources.doctrine.odm.documentManagers.default.proxy.autoGenerateClasses = true resources.doctrine.odm.documentManagers.default.proxy.namespace = "DocumentProxy" resources.doctrine.odm.documentManagers.default.proxy.dir = APPLICATION_PATH "/data/doctrineDocumentProxies/Proxy" resources.doctrine.odm.documentManagers.default.hydrator.dir = APPLICATION_PATH "/data/hydrator" resources.doctrine.odm.documentManagers.default.hydrator.namespace = "Hydrators" resources.doctrine.odm.documentManagers.default.metadataDrivers.annotationRegistry.annotationFiles[] = "Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php" resources.doctrine.odm.documentManagers.default.metadataDrivers.drivers.0.adapterClass = "DoctrineODMMongoDBMappingDriverAnnotationDriver" resources.doctrine.odm.documentManagers.default.metadataDrivers.drivers.0.mappingNamespace = "ApplicationDocument" resources.doctrine.odm.documentManagers.default.metadataDrivers.drivers.0.mappingDirs[] = APPLICATION_PATH "/../library/Application/Entity" resources.doctrine.odm.documentManagers.default.metadataDrivers.drivers.0.annotationReaderClass = "DoctrineCommonAnnotationsAnnotationReader" resources.doctrine.odm.documentManagers.default.metadataDrivers.drivers.0.annotationReaderCache = "annotationCacheODM" [staging : production] [testing : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 [development : production] phpSettings.display_startup_errors = 1 phpSettings.display_errors = 1 resources.frontController.params.displayExceptions = 1 |
doctrineの動作確認
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ php bin/doctrine.php Doctrine Command Line Interface version 2.3.0 Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v Increase verbosity of messages. --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. |