1. apache的根目录直接指向 symfony/webphp
2. generate:bundlehtml
3. 建立一个数据库(mysql)php console doctrine:database:createmysql
# app/config/config.yml doctrine: dbal: driver: pdo_mysql dbname: Symfony2 user: root password: null charset: UTF8
4. $ php app/console doctrine:generate:entitylaravel
5. $ php console doctrine:schema:update --forcegit
Set your default values directly in the entity file:github
/** * @var varchar $totaltime */private $totaltime =null;
Then add to your yml file:web
totaltime: type:string nullable: TRUE
Then something like:sql
php app/console doctrine:schema:update --dump-sql
To update the database.mongodb
However, you really need to slow down and work you way through the examples in the manual. Guessing at how you did things is really not going to get you very far.数据库
6. Order By
$repository = $this->getDoctrine() ->getRepository('AcmeStoreBundle:Product'); $query = $repository->createQueryBuilder('p') ->where('p.price > :price') ->setParameter('price', '19.99') ->orderBy('p.price', 'ASC') ->getQuery(); $products = $query->getResult();
7. Doctrine2 的事件
The EntityManager and UnitOfWork trigger a bunch of events during the life-time of their registered entities.
http://docs.doctrine-project.org/en/2.0.x/reference/events.html
注意
要使用 annotation 来配置 prePersist . preUpdate 等事件
必需要在对应的yml中的lifecycleCallbacks部分进行定义声明:
/** @Entity @HasLifecycleCallbacks */
class User { // ... /** * @Column(type="string", length=255) */ public $value; /** @Column(name="created_at", type="string", length=255) */ private $createdAt; /** @PrePersist */ public function doStuffOnPrePersist() { $this->createdAt = date('Y-m-d H:m:s'); } /** @PrePersist */
必须是公开方法,不然户出错 public function doOtherStuffOnPrePersist() { $this->value = 'changed from prePersist callback!'; } /** @PostPersist */ public function doStuffOnPostPersist() { $this->value = 'changed from postPersist callback!'; } /** @PostLoad */ public function doStuffOnPostLoad() { $this->value = 'changed from postLoad callback!'; } /** @PreUpdate */ public function doStuffOnPreUpdate() { $this->value = 'changed from preUpdate callback!'; } }
lifecycleCallbacks: prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ] postPersist: [ doStuffOnPostPersist ]
<?php
8. ODM看到哪里:
@ODM\EmbbedOne,
@ODM\EmbbedMany,
@ODM\Document,
@ODM\ReferenceOne
@ODM\Collection(strategy="pushAll")
PHP的原理究竟是什么?
protected $_document_class = '\Documents\User';
$resource instanceof $this->_document_class
$user = new $this->_document_class();
9. composer的使用方法
注意,若是修改了composer.json文件,lock文件必须更新
composer.phar update命令搞定,看下文:
http://www.cnblogs.com/zhepama/p/3543469.html
可是依然被lib-icu的版本问题卡住了,决定暂停一下
若发生icu错误 在php.ini中解除注释 extension=php_intl.dll
http://stackoverflow.com/questions/1451468/intl-extension-installing-php-intl-dll
10. 须要依赖的2个项目已经找到:
mongodb-odm 和 mongodb-bunder
https://github.com/doctrine/mongodb-odm
https://packagist.org/packages/doctrine/mongodb-odm-bundle
放入项目中后:
依赖这篇文章:
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
有空须要看看支持的mongodb数据类型
这篇文章能够看,可是与symfony没有太大关系
经过查看classloader.php的方法findFile能够看到
该类导入其余类依赖于文件composer/installed.json
所以必需要解决composer.phar问题
PHP -m 这个命令看到的是 ext 文件夹下的dll文件,而且若要添加一个dll文件还得将其名字写入 php.ini的extension中
例如 extension=php_mongo.dll
注意: 必定要保证php中添加了 mongo模块,不然安装 mongo-odm和mongo-odm-bundle根本经过不了!
如何安装mongo扩展?
http://blog.csdn.net/aliang702/article/details/15503439
主要分清版本
下载php_mongo.dll的页面: https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
而且肯定ext-mongo是否被安装:
composer.phar show --platform
若用@dev记得将 composer.phar 中的 minimum-stability 设为 "dev"才行
minimum-stability的解释说明
https://getcomposer.org/doc/04-schema.md#minimum-stability
https://github.com/laravel/framework/blob/4.0/composer.json#L88
若发生找不到 git 命令的问题:
首先将git加入系统环境变量中
git.exe在哪里?
http://stackoverflow.com/questions/11928561/where-is-git-exe-located
记得用
php app/console doctrine:mongodb:generate:documents AcmeStoreBundle
生成document的getter和setter
必定记得要手动添加每一个document的yml文件(此处不一样于orm能够自动生成)
# src/Acme/StoreBundle/Resources/config/doctrine/Product.mongodb.yml Acme\StoreBundle\Document\Product: fields: id: id: true name: type: string price: type: float若肯定以上步骤都没有问题后仍然产生 命名空间冲突的错误能够清除cache