Zend Framework 2 + Doctrine 2(Zend 框架 2 + 教义 2)
问题描述
我想开始使用 Zend Framework 进行开发,我想使用 zf2.由于我使用 Doctrine 2,您能否建议一些教程来帮助我将其集成到 zf2 中?谢谢!
I would like to start developing with Zend Framework and I would like to use zf2. Since I use Doctrine 2, can you suggest some tutorials to help me to integrate it in zf2? Thanks!
推荐答案
上次检查:ZF2.2.*, DoctrineORMModule 0.7.
你可能想通过 composer 加载 DoctrineORMModule
:
You may want to load DoctrineORMModule
via composer:
- 将
doctrine/doctrine-orm-module
添加到您的 composer.json 的要求中(格式问题列表 bcs 之后的示例代码) - 运行
php composer.phar 安装
- 创建目录
./data/DoctrineORMModule/Proxy
并确保您的应用程序具有写入权限 - 配置学说通过你的应用程序
/config/autoload
给模块项目特定设置(数据库等) - 在你的模块中配置学说的实体映射
config.php
- 将实体添加到您的项目中
- 将
DoctrineORMModule
和DoctrineModule
添加到您的config/application.config.php
- 运行 cli 工具生成表
./vendor/bin/doctrine-module orm:schema-tool:create
- add
doctrine/doctrine-orm-module
to your composer.json's require (example code after list bcs of formatting problems) - run
php composer.phar install
- create the directory
./data/DoctrineORMModule/Proxy
and ensure write access for your application - configure doctrine via your applications
/config/autoload
to give the module the project-specific settings (database etc) - configure doctrine's entity mapping in your modules
config.php
- add an entity to your project
- add
DoctrineORMModule
andDoctrineModule
to yourconfig/application.config.php
- run the cli tool to generate your tables
./vendor/bin/doctrine-module orm:schema-tool:create
我强烈建议您不要使用 composer,因为它是一种安装依赖项并设置自动加载器的简单方法.ZF2 默认通过 composer 发布.
I strongly discourage you from not using composer, as it is an easy way to install dependencies and have the autoloaders all set up. Also ZF2 ships via composer by default.
{
"require" : {
"php": ">=5.3.3",
"zendframework/zendframework": "2.*"
"doctrine/doctrine-orm-module": "0.*"
}
}
实体设置
<?php
return array(
'doctrine' => array(
'driver' => array(
// defines an annotation driver with two paths, and names it `my_annotation_driver`
'my_annotation_driver' => array(
'class' => 'DoctrineORMMappingDriverAnnotationDriver',
'cache' => 'array',
'paths' => array(
'path/to/my/entities',
'another/path'
),
),
// default metadata driver, aggregates all other drivers into a single one.
// Override `orm_default` only if you know what you're doing
'orm_default' => array(
'drivers' => array(
// register `my_annotation_driver` for any entity under namespace `MyNamespace`
'MyNamespace' => 'my_annotation_driver'
)
)
)
)
);
需要注意的问题:通往实体的路径应该是完全限定的.最好从 __DIR__
开始,否则事情会中断(每个新项目我都想知道为什么命令行工具在我发现这个错误之前不起作用......;)
A gotcha to be aware of: The paths to your entites should be fully qualified. Best start with __DIR__
, else things will break (Every new project I wonder why the command line tool doesn't work until I find this error ... ;)
<?php
return array(
'doctrine' => array(
'connection' => array(
// default connection name
'orm_default' => array(
'driverClass' => 'DoctrineDBALDriverPDOMySqlDriver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'username',
'password' => 'password',
'dbname' => 'database',
)
)
)
),
);
所有代码示例都是官方教条模块自述文件的一部分
Marco Pivetta 做了 关于教义模块使用的精彩演示,我向所有使用此模块的人推荐.
Marco Pivetta made a wonderful presentation about doctrine-module usage, which I recommend to everybody using this module.
Jason Grimes 写了一个教程 在官方模块出现之前,phpdeveloper.org 上的特色应该有助于安装学说.
Jason Grimes wrote a tutorial featured on phpdeveloper.org which should help installing doctrine, before there was an official module.
这篇关于Zend 框架 2 + 教义 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Zend 框架 2 + 教义 2
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01