symfony的相关注意点

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 的事件

10.2. Lifecycle Events

The EntityManager and UnitOfWork trigger a bunch of events during the life-time of their registered entities.

  • preRemove - The preRemove event occurs for a given entity before the respective EntityManager remove operation for that entity is executed. It is not called for a DQL DELETE statement.
  • postRemove - The postRemove event occurs for an entity after the entity has been deleted. It will be invoked after the database delete operations. It is not called for a DQL DELETE statement.
  • prePersist - The prePersist event occurs for a given entity before the respective EntityManager persist operation for that entity is executed.
  • postPersist - The postPersist event occurs for an entity after the entity has been made persistent. It will be invoked after the database insert operations. Generated primary key values are available in the postPersist event.
  • preUpdate - The preUpdate event occurs before the database update operations to entity data. It is not called for a DQL UPDATE statement.
  • postUpdate - The postUpdate event occurs after the database update operations to entity data. It is not called for a DQL UPDATE statement.
  • postLoad - The postLoad event occurs for an entity after the entity has been loaded into the current EntityManager from the database or after the refresh operation has been applied to it.
  • loadClassMetadata - The loadClassMetadata event occurs after the mapping metadata for a class has been loaded from a mapping source (annotations/xml/yaml).
  • onFlush - The onFlush event occurs after the change-sets of all managed entities are computed. This event is not a lifecycle callback.

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数据类型

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/basic-mapping.html

这篇文章能够看,可是与symfony没有太大关系

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/tutorials/getting-started.html

 

经过查看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"才行

 http://stackoverflow.com/questions/17925476/trying-to-install-mongodbbundle-for-symfony-using-composer-but-it-can-not-be-re

minimum-stability的解释说明 

https://getcomposer.org/doc/04-schema.md#minimum-stability

https://github.com/laravel/framework/blob/4.0/composer.json#L88

 

若发生找不到 git 命令的问题:

http://stackoverflow.com/questions/20169348/error-git-was-not-found-installing-laravel-with-composer-windows

首先将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
相关文章
相关标签/搜索